CSS – A Simple Page Using Float

The previous exercise asked to create a page with the following layout:

Header section
Large image goes here.
Smaller image
Smaller image
Smaller image
Footer section

The purpose being to try and use floating elements in a design.

Contents

  1. An Example Using float
  2. Source Code
  3. Notes
  4. Image Credits

An Example Using float

You can see how the page I styled and structured using float looks here.

Source Code

<!DOCTYPE HTML>
<html>
  <head>
    <title>Floating on Dreams</title>
    <meta charset="utf-8"  />

    <style>

      #title {
        font-size: 48px;
        text-align: center;
      }

      #subtitle {
        font-size: 24px;
        text-align: center;
      }

      .main {
        font-family: sans-serif;
        box-sizing: border-box;
        width: 960px;
        margin: auto;
      }

      .header {

      }

      .images {
      }

      .large-image {
          margin: auto;
      }

      .small-image-container {

      }

      .small-image {
          float: left;
          margin: 50px 10px 0 10px;
      }

      .footer {
          text-align: center;
      }

      .clearfix::after {
        clear: both;
        display: block;
        content: "";
      }

    </style>

  </head>
  <body>

    <div class="main">
      <div class="header">
        <p id="title">Floating on Dreams</p>
        <p id="subtitle">A simple page using floats</p>
      </div>

      <div class="images">
        <div class="large-image">
          <img src="28-big-image.jpg">
        </div>

        <div class="small-image-container clearfix">
          <div class="small-image">
            <img src="28-small-1.jpg">
          </div>
          <div class="small-image">
            <img src="28-small-2.jpg">
          </div>
          <div class="small-image">
            <img src="28-small-3.jpg">
          </div>
        </div>
      </div>

      <div class="footer">
        <p>Copyright 2018</p>
      </div>

    </div>

  </body>
</html>

Notes

  1. The first thing that needs to be done is to divide the document into nesting and stacking HTML blocks.
  2. This is one possible way to section the document: 
  3. There is always a Main container which contains all the content. It was set to have a width of 960 pixels.
  4. The Header and Footer blocks are nested inside the main container.
  5. Between the header and footer there is some content. The content (in this case) is images and is contained within an Images container.
  6. Nested inside the images container is a stacking of large and small images.
  7. The large image has its own container
  8. The small floating images are wrapped in their own container so they act like a single block. The small images block has .clearfix applied to it.
  9. Not all the sectioning divs have styling applied since their sole purpose is to provide structure.
  10. While styling could have been applied directly to the img tags, I chose to wrap them in a div because it allows for greater flexibility in the future.
    • Imagine turning those small floating images into a “card”:

      A Pensive Cat

Image Credits

The images I used are courtesy of:

  1. charloisporto : Tranquil nature scene
  2. silviarita : Fruit salad
  3. Ataner007 : Woman meditating
  4. susannp4 : Cat