Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

HTML How to Make a Website CSS: Cascading Style Sheets Center the Wrapper

Tomasz Cysewski
Tomasz Cysewski
2,736 Points

Footer does not work correctly

Hello, I'm trying to make footer work, it aligns along with wrapper, if I delete float:left from galerry items footer works correctly. Whats the matter? Thx for help

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Nick Pettit | Designer</title>
    <style>
      ul{
        margin: 0;
        padding: 0;
        list-style: none;
      }
      #id li{
        float: left;
        width:45%;
        margin: 2.5%;
      }
      img{
        max-width:100%;
      }
      #wrapper {

        max-width: 940px;
        margin: 0 auto;
        padding: 0 5%; }
    </style>
  </head>
  <body>

      <a href="index.html" style="text-align: center">
        <h1>Nick Pettit</h1>
        <h2>Designer</h2>
      </a>
      <nav style="text-align: center; padding: 10px; margin: 20px 0 0;">
        <ul>
          <li><a href="index.html">Portfolio</a></li>
          <li><a href="about.html">About</a></li>
          <li><a href="contact.html">Contact</a></li>
        </ul>
      </nav>
    <div id="wrapper">
      <section >
        <ul id="id" class=" gallery">
          <li><img src="numbers-01.jpg" alt="numbers-01"></li>

          <li><img src="numbers-02.jpg" alt="numbers-01"></li>

          <li><img src="numbers-06.jpg" alt="numbers-01"></li>
          <li><img src="numbers-09.jpg" alt="numbers-01"></li>
          <li><img src="numbers-12.jpg" alt="numbers-01"></li>
        </ul>
      </section>
    </div>

    <footer style="font-size: 0.75em; text-align: center; padding: 50px; color: #ccc; ">
      <p>&copy; 2014 Nick Pettit.</p>
    </footer>
  </body>
</html>
Tomasz Cysewski
Tomasz Cysewski
2,736 Points

I perceived that the width of the section is 0px, when I scale it footer moves

1 Answer

Hi Tomasz

I believe the <section> tag has collapsed because of the floated item. So to fix this, create a clearfix and add it to the <section> tag.

.clearfix::after {
  content: '';
  display: table;
  clear: both;
}

Add to section tag

<section class="clearfix" >