====== Web Development Lesson 8 - Forms ====== ===== Styling ===== ==== Objective ==== In this activity you will improve the appearance of your forms. ==== Setup ==== * We'll continue to use 'form.php' and 'style.css' in this activity. In case you need the code again, here it is. **form.php** prepare($query); $hrslt->execute($args); // get list of movies $query = "SELECT * FROM appearances GROUP BY movie"; $args = array(); $mrslt = $pdo->prepare($query); $mrslt->execute($args); ?>
    • Hero
    • Villain
    • fetch()) { ?>
**style.css** ol { color: blue; } ol ol { font-weight: 700; } ul { list-style-type: none; } td, th { border-width: 1px; border-style: solid; } td { padding: 10px; } table { border-collapse: collapse; } header { background-color:indianred; border:darkred solid 2px; height: 100px; position: absolute; left: 16%; right: 0px; top: 0px; } nav { background-color: burlywood; border:yellow solid 2px; position: fixed; top: 0px; bottom: 0px; width: 16%; left: 0px; } main { background-color: lightgree; border: darkgreen solid 2px; position: absolute; top: 100px; left: 16%; right: 0px; bottom: 80px; overflow: scroll; padding: 20px; } footer { background-color: lightskyblue; border: darkblue solid 2px; position: absolute; bottom: 0px; height: 80px; left: 16%; right: 0px; } .content { background-color:coral; border:orangered solid 2px; height: 400px; padding: 40px; margin: 20px; display: inline-block; width: 300px; } img { float: left; max-height: 250px; border: solid 2px green; margin: 20px 20px 20px 0px; padding: 10px; border-radius: 30px; } #album { display: flex; justify-content:space-between; flex-wrap: wrap; } video { max-height: 250px; float: right; clear: left; margin: 20px 0px 20px 20px; padding: 10px; } audio { margin: 20px 20px 20px 0px; padding: 10px 10px 10px 0px; } input[type=button] { display: block; } figcaption { display: block; text-align: center; font-family: 'Arial', sans-serif; color: green; } ==== Fieldsets ==== * Save and upload the code if you need to. * Open 'form.php' in your browser and take a look. * What do you think needs improving? * The first thing I notice is that everything is piled up together. It needs to be spaced out to make it more readable. * Let's start by separating out the two sections of the form. * Add a
tag just after the
tag and close it just before the closing
tag.
...
...
* Save and upload, then refresh your page. * Now you should have a border around each section, which makes it much clearer. *
divides your form into sets of fields, though in this case each fieldset is its own form. * We can also label each fieldset by adding a legend. This can go anywhere, but is clearest just inside the opening
tag.
Add Hero ...
Add Appearances ...
* Save, upload and check the result. ==== Aligning fields ==== * The simplest way to align everything would be to use a table, but that wouldn't be responsive (wouldn't look good on smaller screens) so we'll use CSS instead. * I like to simulate a table with a column for the labels on the left and a column for the inputs on the right, then align each so that they meet in the middle. * Let's create some space for labels by adding width: 10em;. Remember that em defines space in character widths. From a bit of experimentation, I know that 10em is sufficient for all our labels. * Unfortunately, width can't be applied to inline elements like