A sample page

Notes

In this section we will provide an example of a web page and some styling of it. We start with the HTML for the page.

<!doctype html>
<html>
  <head>
    <title>A sample page</title>
    <link rel="stylesheet" type="text/css" href="reset.css">
    <link rel="stylesheet" type="text/css" href="basics.css">
  </head>
  <body>
    <header>
      <img id="logo" src="https://www.hanover.edu/images/site/logos/logo.png" alt="Our college's athletics logo">
      <h1>An awesome sample page!</h1>
    </header>
    <main>
      <section id="sidebar">
        <nav>
          <h2>Navigation</h2>
          <ul>
            <li><a href="page1.html">A link!</a></li>
            <li><a href="page2.pdf">Another link!</a></li>
            <li><a href="page2.pdf">A third link!</a></li>
          </ul>
        </nav>
      </section>
      <section id="content">
        <h2>Our awesome content!</h2>
        <article>
          <h3>First item</h3>
          <p>Cool content goes in this paragraph. A lot of stuff we can write here.</p>
          <p>Another paragraph within the same item.</p>
        </article>
        <article>
          <h3>Second item</h3>
          <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur pharetra scelerisque varius. Nunc finibus sollicitudin tellus, ac dictum felis semper ut. Vivamus faucibus viverra velit in efficitur. Proin malesuada lectus sit amet diam dictum auctor. Maecenas ac neque non ligula suscipit elementum. Vestibulum a interdum mauris, ac rhoncus nisi. Donec vitae hendrerit diam. In vel metus vel ante posuere eleifend. Quisque vitae sapien convallis, cursus augue eget, congue mauris. Maecenas at sagittis lorem. Ut nec arcu id mi auctor dictum at in risus. Vestibulum pretium venenatis orci ac fermentum. Quisque sollicitudin lacinia sollicitudin. Ut laoreet dolor eget magna rutrum aliquam. Mauris quis luctus ex.</p>
          <p>Donec auctor tincidunt felis nec sollicitudin. Mauris scelerisque in mauris nec semper. Sed sed purus turpis. Nunc viverra, nulla eu ullamcorper euismod, sapien nulla maximus tortor, ac tempor justo nibh id ante. Curabitur sed purus quis lorem vulputate rutrum. Sed eleifend purus sit amet lectus aliquam, eu dictum tellus malesuada. Aliquam at imperdiet erat, quis lacinia velit.</p>
          <p>Morbi ac convallis dui. Cras sed leo ut dui tempus eleifend. Vivamus ac ipsum at nulla porta varius in pretium mi. Praesent sollicitudin congue interdum. Vivamus aliquam dignissim scelerisque. Fusce dapibus, mauris bibendum facilisis condimentum, elit lectus ornare ante, eget pretium sapien urna vel tortor. Etiam non odio vel nisi mollis consectetur. Etiam pharetra dolor at cursus pellentesque. Suspendisse nulla ex, tristique nec euismod vitae, commodo sed sem. Quisque accumsan accumsan justo, at tincidunt nibh vehicula in.</p>
        </article>
      </section>
    </main>
    <footer>Thank you for visiting!</footer>
  </body>
</html>

We start by saving this into a file, and open it up on a browser. It probably doesn’t show at all like we want it to, even though we have semantically described the content well. Let’s look at some of the problems:

Cleanup / CSS reset

A common first step in any page design is eliminating all browser settings. This is often called a CSS-reset. This often ends up being somewhat lengthy. We put it into its own file (reset.css) that loads first.

html, body, div, span, applet, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
a, abbr, acronym, address, big, cite, code,
del, dfn, em, img, ins, kbd, q, s, samp,
small, strike, strong, sub, sup, tt, var,
b, u, i, center,
dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, canvas, details, embed,
figure, figcaption, footer, header, hgroup,
menu, nav, output, ruby, section, summary,
time, mark, audio, video {
   margin: 0;
   padding: 0;
   border: 0;
   font-size: 100%;
   font: inherit;
   vertical-align: baseline;
}
/* HTML5 display-role reset for older browsers */
article, aside, details, figcaption, figure,
footer, header, hgroup, menu, nav, section {
   display: block;
}
body {
   line-height: 1;
}
ol, ul {
   list-style: none;
}
blockquote, q {
   quotes: none;
}
blockquote:before, blockquote:after,
q:before, q:after {
   content: '';
   content: none;
}
table {
   border-collapse: collapse;
   border-spacing: 0;
}

Look at the page after this change. You will see it now looks a mess. But we’ll clean it up.

The rest of the CSS changes will all go into our basics. css file. Though we could in theory have separated some of the changes into different files (for instance of some changes are to be shared with other websites or pages).

Logo adjusting

We start by taming in the logo a bit.

#logo {
   height: 2em;
   width: auto;
   padding: 1px;
   background-color: black;
   border: 1px solid gray;
}

So:

Basic layout

The first big item is specifying the basic layout that will create the different page sections.

header {
  background-color: #D9ECC3;
  padding: 10px;
}

main {
   display: flex;
   flex-direction: row;
}

#sidebar {
   flex: 1;
   padding: 1em;
   background-color: #799657;
}

#content {
   flex: 3;
   padding: 1em;
   background-color: #EFF4E9;
}

footer {
   border-top: 1px solid #4A523F;
   padding: 10px;
}

So here is what is going on:

At this point, let’s go ahead and add: display: flex; to the header rule. This will allow the image and header text to stand next to each other.

Typography

We will now do some styling of the typography of the various sections.

/* Typography */
body {
   font-family: Georgia, Palatino, "Times New Roman", serif;
   font-size: 16px;
   line-height: 1.2;
}

h1, h2, h3 {
   font-family: Verdana, Tahoma, Helvetica, sans-serif;
   font-weight: bold;
}
h1, h2 { text-align: center; }
h1 { font-size: 2em; }
h2 { font-size: 1.414em; }
h3 { font-size: 1em; }

So here is what these lines do:

Spacing

Let us work on spacing the items on the content section a bit, and learn some more tricks along the way:

/* Content area */
main section {
   padding-top: 0.5em;
}

article {
   margin: 1em;
   padding: 0.2em;
   border: 1px solid #EFF4E9;
   border-radius: 7px;
}

article p {
   margin-bottom: 0.3em;
   margin-top: 0.3em;
}

article p:first-of-type::first-letter {
   font-size: 1.414em;
}

article p:last-of-type {
   border-bottom: 1px dashed #999998;
}

article:hover {
   background-color: #E1E6DC;
   border-color: gray;
}

article:hover h3:after {
   content: '\25ca';
   padding-left: 0.2em;
   color: #A2EDF3;
}

Let’s walk through what each of these settings does:

The sidebar

The time has come for us to work on the sidebar. The sidebar contains an unnumbered list of list items, each of which is a link. We’ll create rectangular clickable areas for each of them.

/* sidebar */
#sidebar nav {
   margin: auto;
   width: 80%;
}

#sidebar nav li {
   margin-top: 0.2em;
   margin-bottom: 0.2em;
}

#sidebar nav li a {
   display: block;
   text-align: center;
   text-decoration: none;
   color: black;
   border: 1px solid #5E8251;
   border-radius: 3px;
   background-color: #6DA52A;
}

#sidebar nav li a:hover {
   border-color: #4D6A42;
   background-color: #578322;
}

#sidebar nav li a[href$=".pdf"]:after {
   background-image: url("http://iconbug.com/data/5b/507/52ff0e80b07d28b590bbc4b30befde52.png");
   background-size: 1em 1em;
   display: inline-block;
   width: 1em;
   height: 1em;
   content: "";
}

Let’s see what goes on here: