Working with Forms, Credit Card Info


Activity Instructions

This will have you practice several topics from the last few weeks to create and style a credit card submission form.

Estimated Time: 60 minutes

Our form will be inspired by this codepen example.

Below you can see a mockup of what we want our form to look like when we are done.

mockup for the credit card form we will build and style

01 Organizing our thoughts.

Whenever you start a new project, it is a good idea to list out the steps we will need to follow in order to solve the problem. If we can make our list in small enough steps, each step becomes trivial. That is the goal.

  1. Add a new directory to our project called creditcard. Add an index.html and a stylesheet file. Make sure to add a new link to your main index page for your site to this new page.
  2. Add a form to your page. Inside of that form create an element to act as a card front and another for the card back. Also add a submit button.
  3. Using CSS grid place the card front and card back overlapping like the screenshot. Make sure to place the button as well. Do some basic styling on the containers as well...round the corners, add a background color, you could even add a box-shadow if you wanted. Make sure the back is behind the front. (You can do this either by ordering the HTML elements the right way, or by using z-index Higher numbers put things on the top of the stack.)
  4. Begin adding the form elements to the card front and card back. Remember that a good form input should always have a label to go along with it! A placeholder attribute would also be a good idea. You can use the code below to display the small orange card image.
    <img
    class="card-image"
    src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/PjxzdmcgZGF0YS1uYW1lPSJMYXllciAxIiBpZD0iTGF5ZXJfMSIgdmlld0JveD0iMCAwIDYwIDYwIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIj48ZGVmcz48c3R5bGU+LmNscy0xLC5jbHMtMTAsLmNscy0xMSwuY2xzLTIsLmNscy02LC5jbHMtN3tmaWxsOm5vbmU7fS5jbHMtMXtjbGlwLXJ1bGU6ZXZlbm9kZDt9LmNscy0yLC5jbHMtNXtmaWxsLXJ1bGU6ZXZlbm9kZDt9LmNscy0ze2NsaXAtcGF0aDp1cmwoI2NsaXAtcGF0aCk7fS5jbHMtNHtjbGlwLXBhdGg6dXJsKCNjbGlwLXBhdGgtMik7fS5jbHMtNXtmaWxsOiNmZTg2NTc7fS5jbHM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based on the mockup.
  6. Do the same for the card back.
  7. Use margin, padding, and alignment properties to finish up the layout.
  8. Add some HTML validation to your form inputs. For example, all of the fields should be required. Some should have specific lengths, etc.

02 Hints and Tips

If you are having difficulties working through the list of steps above, scan through the list below and see if there is something that can help!

HTML structure of the form elements

Getting your HTML structure correct can make a big difference in how smoothly your layout comes together. See the screenshot below for an example of how you might group certain elements in your HTML. Each of the red boxes represents an HTML element. Notice how each item that I wanted to place directly on the grid is grouped together with an element.

screenshot showing element structure
Main Grid

If you are having a hard time getting the main grid to work (this is the one that places the card front, card back, and submit button) take a look at the screenshot below for some hints. (the wide darker lines indicate that a gap was used).

screenshot showing main grid lines
Card Front Grid

If you are having a hard time getting the card front grid to work, take a look at the screenshot below for some hints. (the wide darker lines indicate that a gap was used). Notice as well that there is a space all the way around the grid...how does one add space on the inside of an element?

screenshot showing card front grid lines
Card Back Grid

If you are having a hard time getting the card back grid to
work, take a look at the screenshot below for some hints. Notice
as well that there is a space on the top and bottom of the
grid...how do you add space on the inside of an element?

To create the dark grey bar on the card back you can just use an empty div. Set a background-color, and a height, then position it in your grid.

screenshot showing card back grid lines
Spacing and alignment.

Because we are using CSS Grid we have access to all of it's
alignment properties. These include
justify-content, justify-items, align-items, align-self, justify-self. You can review this CSS Grid Cheatsheet for a refresher about what each does if you need it.

You can accomplish a lot with some well placed margin and padding as well!

03 Add a Favicon

Part of your exploration this week was on Favicons. Apply what you learned by adding a favicon to this page. You can easily create a custom one.

  1. Open up the Pixlr editor. (If you have another editor you like you can use that as well)
  2. Click "Create new", switch to the Web tab and select "Icon 32"
  3. Select the Text tool and click on the image (You may find this easier if you zoom in to make it bigger) Set the font size to about 18-20 and enter "131" (or your initials if you would like). Center the text and change the color to something you like.
  4. Save your image in the creditcard directory as favicon.png
  5. Add the link to your HTML file to use your new favicon

04 Commit and push to Github

Commit your changes, then push them to GitHub. Wait a few minutes then check to make sure they show on Github pages. If you need a review on how to do this check out github instructions. Start around step 3.

Remember your metadata! This week we have another new addition.

  • Meta Charset Attribute
  • Title Element
  • Viewport Meta Element
  • Meta Description Element: Short description of the site
  • Meta Author Element
  • Favicon link: New
  • Link reference to your CSS file.
  • Script Element linking to a Javascript file (When using Javascript)

For more information see: MDN: What's in the Head?

After verifying that your page updated, submit the URL to your page in Ilearn. The URL will look something like this: https://githubusername.github.io/wdd131/creditcard. Make sure to replace "githubusername" with your actual github username :)