Laying out a complex footer

In the following steps, we'll create a complex footer built to manage multiple goals, including these: three lists of links to key sections of our website, a bit of About Us text, social icons, and our logo.

Setting up the markup

We will start by creating the footer markup. We want this footer to be as functional and useful for the user as possible. We'll build the markup as follows:

  1. Find the file footer-content.html in the project folder 04_Code_BEGIN. Open it in your editor, and copy the entire content to the clipboard.
  2. Now, back in index.html, find the place where we want to paste this content. It's within footer role="contentinfo", just after div class="container" and before ul class="social". (I've placed a comment there to help you find the spot.)
  3. Before pasting the content, let's prepare to utilize the Bootstrap grid system. To do this, we'll wrap the area within div class="row", as follows:
    <footer role="contentinfo">
      <div class="container">
        <div class="row">
          <!-- INSERT ADDITIONAL FOOTER CONTENT HERE -->
        </div><!-- /.row -->
        <ul class="social">
  4. Now, paste the new content in place.
  5. Next, we'll wrap each of the three lists of links along with their headings within div of class col-md-2. This way, each list will take one-sixth of the available width in medium and larger viewports. Together, these three lists will take half the available viewport width.
    <div class="col-md-2">
      <h3>Categories</h3>
  6. Now to complete our row, wrap the About Us heading and its paragraph in div of class col-md-6 so that it takes up the remaining half of the available width:
    <div class="about col-md-6">
      <h3>About Us</h3>

    Tip

    Be sure to add the necessary closing tags for each new div element.

  7. Save, refresh, and check your results.

In a viewport of 980px and larger, our columns should organize themselves as follows:

Setting up the markup

This is the layout we want in medium and larger viewports. Extra-small screen sizes are served just fine by the single-column layout. However, for tablet-width screen sizes that fall within the range of 768 to 980 pixels, our layout can benefit from some adjustments. Let's address that.

Adjusting for tablet-width viewports

Test the layout in a viewport that falls between 768 and 980 pixels. Bootstrap refers to this as the small breakpoint, with the @screen-sm variable and col-sm- grid classes. At this width, the single-column layout leaves unnecessary white space. Here is what you'll see:

Adjusting for tablet-width viewports

We can improve this layout by allowing our three lists of links to float next to each other. Using the Bootstrap col-sm- column classes, let's set the three lists of links to be one-third width, or col-sm-4, and the About Us column to be full width, or c ol-sm-12.

<div class="col-sm-4 col-md-2">
...
<div class="col-sm-4 col-md-2">
...
<div class="col-sm-4 col-md-2">
...
<div class="about col-sm-12 col-md-6">

Save this and try it out in the small viewport range. You will see the following result:

Adjusting for tablet-width viewports

Much improved! But we're not quite finished. Try clicking on the links in the upper three columns. Chances are that you won't be able to. Inspect the element and you'll find that the fourth div element contains the code for the About Us column. This code does not clear the floated columns above it. Though the About Us heading and its paragraph will appear below the three floating columns, the div element itself will overlap them.

Adding a targeted responsive clearfix

In a standard Bootstrap layout situation, we would use a div element with the row class to clear the floating columns above. Here, we need a different solution, as we want this block of content to clear floats only within this specific breakpoint.

To accomplish this, we could write custom styles in our LESS files. But we can also use a Bootstrap responsive utility class to provide a targeted clearfix directly in the markup. Since we've already specified grid classes in our markup, let's use the second option in this context.

You can find the approach we'll use mentioned in Bootstrap's documentation at http://getbootstrap.com/css/#grid-responsive-resets. Following that method, we'll create a div element with the class clearfix, and add a Bootstrap responsive utility class to make it visible only on small screens. We'll place this new div element immediately prior to the About Us column:

<div class="clearfix visible-sm"></div>
<div class="about col-sm-12 col-md-6">

The clearfix class will force this element to clear the floats above it. The visible-sm class will allow this div to display only within our targeted breakpoint. At other breakpoints, it will be as if this div does not exist.

Save this, refresh your browser, and you should find that the About Us column now clears the floats above it and that the links are clickable.

Task complete. Now for a few finishing touches.

Refining the details

We have a few last touches we want to implement as we finish our footer. These include the following:

  • Refining the presentation of our three lists of links
  • Adjusting margins and padding
  • Reversing the color scheme to match our navbar colors

To accomplish these refinements, we'll write some custom styles. Let's tackle this in cascading fashion, starting with general rules for the footer and moving to the specific rules:

  1. Open _footer.less, the file for custom footer styles, in your editor.

    Here you'll find some initial rules that I've carried over with slight modifications from Chapter 2, Bootstrappin' Your Portfolio. These include some initial padding for the footer as well as styles for the social icons and the footer version of the logo.

  2. Now to add the refinements we need for our new complex footer. Let's start by reducing the footer font size and inverting the color scheme to correspond with the inverted navbar—a blue background with light text. I'll begin with those colors and then darken them slightly. To do this, I'll make use of appropriate variables from _variables.less, including @font-size-small, @navbar-inverse-bg, and @navbar-inverse-color:
    footer[role="contentinfo"] {
      padding-top: 24px;
      padding-bottom: 24px;
      font-size: @font-size-small;
      background-color: darken(@navbar-inverse-bg, 18%);
      color: darken(@navbar-inverse-color, 18%);

    Tip

    In this and all that follows, we need to nest our new rules within footer[role="contentinfo"].

  3. Next, we need to adjust our links and buttons to fit the new color scheme. Still nesting rules within footer[role="contentinfo"], I've done this as follows:
    a {
      color: @navbar-inverse-color;
      &:focus,
      &:hover,
      &:active {
        color: @navbar-inverse-link-hover-color;
      }
    }
    .btn-default {
      color: darken(@navbar-inverse-bg, 18%) !important;
    }
  4. Now to address the four h3 headings. I'll adjust font size, trim the bottom margin, and convert the text to uppercase:
    h3 {
      font-size: 120%;
      margin-bottom: 4px;
      text-transform: uppercase;
    }
  5. Having done this, we can next remove bullets from our list of links, and adjust their padding and margin.
    ul {
      list-style: none;
      padding: 0;
      margin: 0;
    }

    Tip

    For the purposes of this exercise, I've applied these rules to all unordered lists within the site footer. Depending on the needs of your footer, you may want to use a special class for these lists of links, such as, footer-nav.

  6. Lastly, let's adjust our social icons. We'll add a bit of top padding and then adjust their colors to work better with the new color scheme. Since these are Font Awesome icons, we can do this simply by adjusting the color and background-color values, as follows:
    ul.social {
      ...
      padding: 24px 0 0;
      ...
      > li {
        ...
        > a {
          ...
          background-color: darken(@navbar-inverse-bg, 27%);
          color: darken(@navbar-inverse-color, 18%);
          ...
          &:hover {
            ...
            background-color: darken(@navbar-inverse-bg, 32%);
            color: @navbar-inverse-link-hover-color;
          }
        }
      }
    }

That's it. Save, compile, refresh, and enjoy! Here is our result in medium and wide viewports:

Refining the details

And here is the result for small viewports:

Refining the details

And this is for extra-small viewports:

Refining the details

Not bad! We have built a footer capable of managing a complex array of content across the full spectrum of extra-small, small, medium, and large viewports.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset