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

CSS

Kyle Vassella
Kyle Vassella
9,033 Points

How to force .header to span the full width of the page?

For this project I dislike the look of the header - I'd prefer it to go all the way across the page.

I tried adding width: 100%; to my css .header selector, but it did not work. Can someone tell me some CSS I can add to make my .header class run the entire width of the page? (.header is on the very bottom of my CSS file)

/*
  AGENCY - A Treehouse template
  by: http://teamtreehouse.com
  v.1.0.1
  License: MIT http://opensource.org/licenses/MIT
*/

/*Main*/

body{
  color: #B1B9C1;
  font-size: 1em;
  font-weight: 200;
  font-family: 'Roboto', Helvetica, Arial, serif;
  width: 100%;
  text-align: center;
  padding-top: 50px;
}

a {
  color: #5FB6E1;
  text-decoration: none;
}

a:hover {
  color: #53A4C4;
}

img {
  width: 100%;
}

ul li {
  list-style-type: none;
}

.row {
  max-width: 1280px;
  margin: 0 auto;
}

/*Typography*/
p {
  margin-bottom: 40px;
}
h1, h2 {
  font-weight: 400;
  width: 100%;
}
h1 {
  ;
}
h2 {
  font-size: 42px;
  color: #465058;
  margin: 40px 0 0;
}
h3 {
  font-weight: 400;
  font-size: 24px;
  margin: 40px 0 0;
  color: #465058;
}
h4 {
  font-weight: 200;
  font-size: 24px;
  margin: 10px 0 0;
}
h5 {
  font-weight: 300;
  font-size: 20px;
  margin: 10px 0 40px;
}

/*Logo*/
.logo {
  width: 80px;
  height: 24px;
  display: block;
  float: left;
  margin: 20px 0;
  background: url('../img/logo.svg') left center no-repeat;
  background-size: 80px 16px;
}
.description {
  line-height: 60px;
  width: 100%;
  font-size: 1em;
  font-weight: 300;
  margin: 0;
  padding: 0;
  display: block;
}

/*Nav*/
nav {
  float: right;
}
nav a {
  transition: .35s linear;
  padding: 0 10px;
  font-weight: 500;
  line-height: 60px;
  color: #B1B9C1;
  text-align: right;
}
nav a:last-child {
  padding-right: 0;
}
nav a:hover {
  color: #333;
}
nav a.active {
  color: #465058
}

/*Button*/
.button {
  border: 2px solid #D5DDE4;
  border-radius: 4px;
  padding: 12px 20px;
  color: #777B7E;
  transition: .35s;
  font-weight: 400;
}

.button:hover {
  border-color: #7CCEEE;
}

/*Slides*/
.slides {
  width: 100%;
  height: 100%;
  margin: 0 auto 40px;
}
.slide {
  width: 100%;
  height: 100%;
}
.slide h2 {
  margin: 25% 0 20px;
  color: #fff;
}
.slide p {
  width: 60%;
  margin: 0 20% 40px;
  font-size: 26px;
  color: #fff;
}
.slide .button {
  color: #fff;
  border-color: #fff;
  opacity: .6;
}
.slide .button:hover {
  opacity: 1;
}
.slide img {
  width: 50%;
  margin: 100px 50% 100px 10%;
}
.blue {
  background: #3E89BE;
}
.orange {
  background: #F8835A;
}
.green {
  background: #5ECE7F;
}
.yellow {
  background: #FFD365;
}
.slick-dots {
  position: absolute;
  width: 100%;
  bottom: 20px;
  left: 0;
}
.slick-dots li button:before {
  font-size: 16px;
  color: #fff;
}
.slick-dots li.slick-active button:before {
  color: #fff;
}

/*Footer*/
footer {
  margin: 80px 0;
  float: left;
  width: 100%;
}
.social {
  margin: 0;
  padding: 0;
}
.social li a {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  border: 10px solid #ccc;
  opacity: .65;
  transition: .35s linear;
}
.social li a:hover {
  opacity: 1;
}
.social .pink {
  border-color: #FF8DB3
}
.social .light-blue {
  border-color: #7CCEEE
}
.social .dark-blue {
  border-color: #3E89BE
}

/*Work Page*/
.frame {
  padding: 20%;
  border-radius: 10px;
  margin: 40px 10px 0;
}
.item {
  margin-bottom: 40px;
}

/*Sticky*/
.is-sticky h5 {
  width: 100%;
  position: fixed;
  top: 0px;
  background: #fff;
  padding: 12px 0;
  margin: 0;
  opacity: .95;
}

/*Team*/
.team {
  margin-bottom: 60px;
}
.avatar {
  width: 50%;
  display: block;
  border-radius: 50%;
  margin: 0 25%;
}

/*Grid*/
.grid-full {
  width: 100%;
  float: left;
}
.grid-half {
  width: 50%;
  float: left;
}
.grid-third {
  width: 27.33333%;
  margin: 0 3%;
  float: left;
}
.grid-fourth {
  width: 25%;
  float: left;
}
.grid-fifth {
  width: 20%;
  float: left;
}

/*Media Quiries*/
@media (max-width: 1000px) {
  .slides p {
    font-size: 18px;
  }
  .grid-fifth {
    width: 27.333333%;
    margin: 0 3%;
  }
}
@media (max-width: 700px) {
  .logo {
    float: none;
    margin: 20px auto 0;
  }
  .grid-half {
    width: 80%;
    margin: 0 10%;
  }
  .grid-third {
    width: 80%;
    margin: 0 10%;
  }
  .grid-fifth {
    width: 80%;
    margin: 0 10%;
  }
  .row {
    padding: 0 10px;
  }
  nav {
    width: 100%;
  }
  nav a {
    transition: 0s;
    width: 33.333333%;
    float: left;
    padding: 0;
    margin: 10px 0 0;
    text-align: center;
  }
  .description {
    display: none;
  }
  .slide img {
    width: 80%;
    margin: 100px 10%;
  }
  .slick-dots {
    top: 20px;
  }
  .frame {
    margin: 40px 0 0;
  }
  .item {
    margin-bottom: 60px;
  }
  .item h3 {
    margin-top: 20px;
  }
  h4 {
    font-size: 20px;
  }
}



.header {
  background-color: black;
  width: 100%;
}
<!DOCTYPE html>
<html class="no-js">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <title>Agency - A Treehouse template</title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <!--CSS-->
        <link href='http://fonts.googleapis.com/css?family=Roboto:400,100,300,500,700,900' rel='stylesheet' type='text/css'>
        <link rel="stylesheet" href="css/normalize.min.css">
        <link rel="stylesheet" href="js/animsition/animsition.min.css">
        <link rel="stylesheet" href="css/main.css">
    </head>
    <body>
      <div class="row container animsition">
        <header class="row header">
          <div class="grid-third">
            <a href="index.html" class="logo"></a>
          </div>
          <div class="grid-third">
            <h1 class="description">We build apps</h1>
          </div>
          <div class="grid-third">
            <nav>
              <a href="#" class="active">Home</a>
              <a href="work.html" >Work</a>
              <a href="team.html" >Team</a>
            </nav>
          </div>
      </header><!--/header-->
        <div class="row">
          <div class="grid-full">

          </div>
          <div class="main row">
            <div class="grid-third">
              <img src="img/sticker-team.png" alt="" />
              <p>United we stand divided we fail.  Meet the all star team behind the agency.</p>
              <a href="team.html" class="button">Meet the Team</a>
            </div><!--/team-->
            <div class="grid-third">
              <img src="img/sticker-work.png" alt="" />
              <p>Check our latest app builds or download them in the App Store.</p>
              <a href="work.html" class="button">Latest Projects</a>
            </div><!--/work-->
            <div class="grid-third">
              <img src="img/sticker-contact.png" alt="" />
              <p>Have questions or requests?  Feel free to contact us, we’d love hear from you.</p>
              <a href="#" class="button">Contact Us</a>
            </div><!--/contact-->
          </div>
        </div><!--/main-->
        <footer>
          <div class="row">
            <div class="grid-full">
              <p>Connect with us</p>
              <ul class="social">
                <li>
                  <a href="#" class="pink"></a>
                  <a href="#" class="light-blue"></a>
                  <a href="#" class="dark-blue"></a>
                </li>
              </ul>
            </div>
          </div>
        </footer><!--/footer-->
        </div>
        <script src="js/jquery-1.11.2.min.js"></script>
      <script src="js/animsition/jquery.animsition.min.js"></script>
      <script src="js/sticky/jquery.sticky.js"></script>

      <script src="js/main.js"></script>
    </body>
</html>

For the sake of brevity I've left out the sticky plugin file and jquery library, and I've also removed the StickyJS jquery plugin because it's not part of my problem.

2 Answers

Oliver Duncan
Oliver Duncan
16,642 Points

In your HTML, it looks like you accidentally put the opening header tag inside of the first div. Switch them, and the header will take up 100% of the body instead of 100% of the first div, as it's doing now.

Kyle Vassella
Kyle Vassella
9,033 Points

I've tried that but still get the same result. This HTML is actually from a lesson on jQuery plugins done by Dave. I just didn't like the look of the header on my browser.

Anything else come to mind? What you said makes sense. Right after I posted this I remembered that the responsive units (percentages, ems, etc) relate to the size of the parent element. But for some reason the width of this header won't budge. Besides only moving the starting header tag, I also tried moving the closing header tag outside of the divs (on a seperate instance) and this also did not work :(

Oliver Duncan
Oliver Duncan
16,642 Points

I messed around with it a bit and got the header to span all the way across the page. Keep in mind that I just cut and paste your code into sublime, and therefore didn't have access to the animsition plugin, the normalizer style sheet, or any javascript. I'm not sure how these files will affect the following solution.

What I did was switch the tags, remove the '.row' class from the header, add 'margin: 0' to the body and .header. After that, the header background-color still wasn't showing up, so I added an 'overflow: auto' to uncollapse it. I suspect you won't have to do that with the animsition plugin, but who knows? Hope this helps.

Kyle Vassella
Kyle Vassella
9,033 Points

I still could not get it to replicate. Perhaps I'm moving the <header> to the wrong spot - it's more confusing now because I'm further into the project and have added many more divs and another plugin. Or maybe the plugins themselves are preventing the full span (though I suspect it's just something I'm not doing correctly).

Either way, thank you very much for taking the time to reply and to figure that out for me. There are several techniques I'll take away from your posts and use to my advantage in the future. Thanks bro