Thumbnail Grid Layout Instructions

Semantic Markup

Your starting point should look like step-1.html

The starting html contains a list of thumbnails and links. Each list item looks similar to this:

<li>
  <img src="images/clock_thumb.jpg" alt="alarm clock" />
  <p class="description">Analog Travel Alarm Clock Braun
    <span class="price">$40.00</span>
  </p>
</li>
  1. We can make this markup more meaningful by using the figure and figcaption elements. Review proper usage here: http://html5doctor.com/the-figure-figcaption-elements/

    Modify the first couple of list items to include figure and figcaption elements. You should not need to remove any markup.

    When finished, each thumbnail block should be marked up like the following:

    <figure>
        <img src="images/clock_thumb.jpg" alt="alarm clock" />
        <figcaption>
            <p class="description">Analog Travel Alarm Clock Braun
                <span class="price">$40.00</span>
            </p>
        </figcaption>
    </figure>
    
  2. The thumbnails should also be links to their respective product pages. Let’s wrap the entire figure in a link. As of HTML5, it’s ok to wrap a block level elements with a link.

    <a href="#" title="View product details">
        <figure>
            <img src="images/clock_thumb.jpg" alt="alarm clock" />
            <figcaption>
                <p class="description">Analog Travel Alarm Clock Braun
                    <span class="price">$40.00</span>
                </p>
            </figcaption>
        </figure>
    </a>
    
  3. Let’s also center our page and set a max-width of 1200px. We can use the container class on the outermost div for that.

  4. Set the margin on the body to be 1em on the top and 5% on the left and right.

Create a grid

Your starting point should look like step-2.html
  1. We have to make the thumbnails line up in a grid. We have 8 thumbnails and we’ll align them in a 4x2 grid.

  2. Make the thumbnails line up by floating each li to the left

  3. Our images are breaking out of their containing boxes because they are too big. Images are one of the few content elements that will not reflow to fit inside their containers.

  4. Our thumbnail blocks are very big. Use the web inspector to look at one of the figure elements. Notice that it has a lot of margin applied to it. This is a browser default that is not getting reset by the reset.css (because figure is an html5 element).

  5. Change the width of each li to 24%

  6. Our elements are only lining up three across. This is because our width and margin together equals more than 100% of the container width, causing the last item to bump down a line.

    24% * 4 + 1.33% * 4 = 101.32%

    Because we added a margin to the right of each item, we actually added an unnecessary margin to the right of the last item in each row. Removing just this last margin will make our rows fit across the page.

    We need to remove the margin on the last item of each row. We can do this using the nth-child pseudo-selector.

    .thumbnail-grid li:nth-child(4n) {
      margin-right: 0;
    }
  7. Our footer text is sneaking into the extra space in our grid. We need to make sure it clears all of the floats in our thumbnail grid. Use the clear property for this.

  8. Depending on page width, the Boskke cube image might be breaking the grid.

  9. There should be more space between the thumbnail grid and the footer. Add a bottom margin of 3em to the ‘thumbnail-grid’.

    .thumbnail-grid {
      margin-bottom: 3em;
      background: rgb(0, 0, 255);
      padding: 1em;
    }

Style the captions

Your starting point should look like step-3.html
  1. We want to style the captions and price so that the price is on the right side of the thumbnail. We’ll achieve this by careful use of positioning.

  2. Absolutely position the price class to the top right.

      .thumbnail-grid .price {
        position: absolute;
        right: 0;
        top: 0;
    }
    

    That made all of the prices go to the top right of the browser window. This is because we positioned them absolutely, relative to the browser window. That is the default behavior with absolute positioning. Instead, we want to position them relative to the description.

      .description {
        position: relative;
    }
    
  3. We want to make sure our text doesn’t overlap, so we’ll add a right padding of 25% to the description class. Then set the width of the price to 25%.

  4. Right align the price text to make it look better.

Create an overlay on hover

Your starting point should look like step-4.html
  1. When we hover over a thumbnail, we want a colored overlay to show over the picture with some text. Look at final.html for an example.

      <a href="#" title="View product details">
        <figure>
            <span class="overlay"></span>
            <img src="images/clock_thumb.jpg" alt="alarm clock" />
            <figcaption>
                <p class="description">Analog Travel Alarm Clock Braun
                    <span class="price">$40.00</span>
                </p>
            </figcaption>
        </figure>
    </a>
    
  2. We want to position the overlay so that it is exactly the same size as the image. Set it to 100% width and height in the css.

  3. The overlay now covers the entire figure element, including the caption. We only want it to cover the element. To do this, we need to create a new container for the overlay which only contains the element.

    <a href="#" title="View product details">
       <figure>
           <div class="thumbnail">
               <span class="overlay">View</span>
               <img src="images/clock_thumb.jpg" alt="alarm clock" />
           </div>
    
           <figcaption>
               <p class="description">Analog Travel Alarm Clock Braun
                   <span class="price">$40.00</span>
               </p>
           </figcaption>
       </figure>
    </a>
    
    • Relatively position the new container. What happens?
  4. Style the text on the overlay.

    background-color: rgba( 255, 0, 0, .5);
    color: white;
    font-weight: bold;
    font-size: 200%;
    padding-top: 40%;
    text-align: center;
    
  5. Get rid of the tiny gap below the images. This happens because they are inline by default. Set our thumbnails to display block. Add a little margin below each image too.

    .thumbnail-grid img {
        display: block; /* Get rid of tiny space below images */
        margin-bottom: .3em;
    }
    
  6. We only want the overlay to show when we’re hovering over the thumbnail.

  7. To create a more smooth effect, we can use CSS transitions to make the overlay gradually fade in.

    .thumbnail-grid a .overlay {
        transition: 1s all;
    }
    

Finished Demo

Your finished thumbnail grid should look like final.html