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

Armando Abrahamsson
Armando Abrahamsson
1,391 Points

Collapse header; not displaying my content.

Hey guys. I'm working on a personal project and want to make a collapsing header, meaning the banner collapses when scrolling down (replacing it with the content). Here is a demo of what I mean.

http://line25.com/wp-content/uploads/2013/header-effect/final-demo/index.html

In any case. I cannot seem to find the issue as to why my content isn't showing.

Here's my code.

<html lang="en">
<head>
  <meta charset="UTF-8">
  <link rel="stylesheet" href="css/main.css">
  <link href='http://fonts.googleapis.com/css?family=Arvo|Lobster+Two|Open+Sans+Condensed:300' rel='stylesheet' type='text/css'>

  <title>Collapsing Header Effect</title>

</head>
<body>
<div id="container">
  <header>
    <h1>This is my header</h1>
  </header>
  <div id="banner">
    <h2>This is the banner</h2>
  </div>
  <div="content">
  <p>Lorem ipsum dolor sit amet, 
    consectetur adipisicing elit. 
    Itaque fuga dolorem, omnis.</p>
  </div>
</div>
</body>
</html>
header{
  height:100px;
  background-color:#dbdbdb;
width:100%;
z-index:10;
position:fixed;
}

#banner{
  width:100%;
  height: 500px;
  position:fixed;
  top:100px;
  background:#707070;
}

#content{
  width: 100%;
  position: relative;
  top:400px;
  background:#ebebeb;
  height:1500px;
  z-index:9;
}

2 Answers

Wayne Priestley
Wayne Priestley
19,579 Points

Hi Armando,

First a typo,

  <div="content"> <!-- should be div id="content" -->

Then you want

#banner{
  width:100%;
  height: 500px;
  position:fixed;
  top:100px;
  background:#707070;
  z-index: 0; <!-- add this -->
}

Hope this helps.