Step 7

More styling!

  • Let's put a border around the "output" (the stuff we shall display once the zzz button is clicked).

  • Wrap the content after zzz button in a <div></div> tag:

<div>
    <p>It takes the average human fourteen minutes to fall asleep.</p>
    <p>If you head to bed right now, you should try to wake up at one of the following times:</p>
    <p>11:44 PM or 1:14 AM or 2:44 AM or 4:14 AM or 5:44 AM or 7:14 AM</p>
    <p>A good night's sleep consists of 5-6 complete sleep cycles.</p>
</div>

HTML <div> tag defines a division or a section in an HTML document. You can think of it as a container for other HTML elements - which is then styled with CSS or manipulated with JavaScript.

  • Now add the following to the end of the <style> section (right before the closing tag </style>):
div {
    border: 3px solid white;
    margin-top: 20px;
}
  • The border and margin-top properties are descriptive. The px is short for pixel, a unit used to express length.

  • Save the index.html file; refresh the index page in the browser.

  • There are several different units for expressing length. For example, try the following:

div {
    border: 3px solid white;
    margin: 1em 5em 1em 5em;
}

The <div> is a common element. If we were to expand this web app in the future, we would likely have many more div elements. The above styling will be applied to all div elements. It would be forward-thinking to ensure the styling is applied only to the div that contains the "output."

<div class="output">
  • Update the div CSS selector to .output
.output {
    border: 3px solid white;
    margin: 1em 5em 1em 5em;
}

Classes allow CSS (and Javascript) to select and access specific elements. Note the style selector for a class starts with a dot as in .output.

  • Save the index.html file; refresh the index page in the browser.