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 trialCool Beans
6,937 Pointsmy banner does sticks only before <h2>Border</h2>. Can you tell me why? here's my code:
my code:
* {box-sizing:border-box;}
article {
margin-top: 5rem;
}
header {
position:fixed;
top:0;
left:0;
width: 100%;
background-color: #294969;
color: ghostwhite;
padding: 10px 15px;
border: 12px solid green;
border-bottom-color: #cf7919;
margin-top: 0px;
margin-right: 5px;
margin-bottom: 20px;
margin-left: -1px;
}
section {
padding:1rem;
border-bottom:2px dotted #666;
background-color:azure;
z-index: -1;
}
a {
display: inline-block;
background-color: tomato;
width: 200px;
}
.hide {
display: none;
}
figure {
position: relative;
margin: 0;
max-width: 480px;
}
figcaption {
position: absolute;
width: 100%;
bottom: 20px;
background-color: yellow;
text-align: center;
}
aside img, #bio {
width:100%;
max-width:600px;
}
#bio {
padding: 2rem;
border: 5px dotted orange;
background-color: mistyrose;
}
footer {
width:200px;
padding:4px;
border:2px solid #ffa949;
margin:30px auto 15px;
color: #294969;
font-size: 10px;
}
main {
margin-left: 2px;
}
#interesting-banner {
position: sticky;
top: 0;
padding: 10px 15px;
border: 12px solid lightsalmon;
margin: 0 -8px;
background: firebrick;
color: white;
font-weight: bold;
}
article, main, section {
overflow: visible;
}
1 Answer
Travis Alstrand
Treehouse Project ReviewerHiya Cool Beans ! đź‘‹
I'm not sure I completely understand the question but it sounds like your header isn't 'sticking' throughout the whole page?
I opened up the workspace attached to the video you posted this on and copy/pasted your provided CSS over what was in there. Everything seems to be working fine on my end with your code. The header sticks as far down as I can scroll.
I would first make sure you've saved your files and refresh the preview in the browser.
If there's no change, I would ensure the HTML is structured the same as it was when opening the workspace initially. Here's what was on mine...
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Developer Diane's blog</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<header>
<div id="logo">Developer Diane’s Blog</div>
</header>
<article>
<section>
<h1>The verdict is in. CSS Layout is great!</h1>
<p>I’ve been working with CSS for a while now, and I have to say, it’s pretty awesome. I love being able to separate content from presentation, and to keep all my styles in an external stylesheet.</p>
<p>I’ve had a pretty good grasp on the basics for a while now, but I needed to learn more about how to control layout with my CSS. Understanding CSS layout meant first exploring the parts of the CSS box model.</p>
</section>
<section>
<h2>The CSS Box Model</h2>
<p>There are lots of great resources online to help you learn the CSS Box Model. I like the CSS Tricks article <a href="https://css-tricks.com/the-css-box-model/" target="_blank">The CSS Box Model</a> by Chris Coyier. To quote the author:</p>
<blockquote>At the risk of over-repeating myself: <strong>every element in web design is a rectangular box.</strong></blockquote>
<p>That’s right! Every HTML element is considered by the browser to be a rectangular box.</p>
<img src="https://i0.wp.com/css-tricks.com/wp-content/csstricks-uploads/thebox.png?resize=570%2C248" alt="illustration of the CSS box model">
<p>The CSS Box Model consists of four properties: content, padding, border, and margin. I've included a graphic from Coyier’s article to illustrate this principle.</p>
<p>It’s pretty easy to understand the Content portion of the box model. The content is whatever your HTML consists of. It could be a paragraph full of text, or a bulleted list, or an image.</p>
<p>Beginning developers may have some trouble keeping the other parts of the box model straight, so let’s examine them one by one.</p>
</section>
<section>
<h2>Padding</h2>
<p>Padding immediately surrounds the content area. Padding is often used to give the content area some breathing room by separating the content from the surrounding border area.</p>
</section>
<section>
<h2>Border</h2>
<p>The border area of the box is the outermost part of the box. You can think of it as giving the rectangular box an outline. Borders tend to be hidden on most CSS elements by default, but once visible different styles like color and thickness can be applied to them.</p>
</section>
<section>
<h2>Margin</h2>
<p>Finally, the margin area exists outside of the box. Margin is the space around an element that separates it from other elements. </p>
<p>It’s important to remember that padding and border affect the size of a CSS box, but margin doesn’t.</p>
</section>
</article>
<aside>
<h3>About me</h3>
<figure>
<img src="developer-diane.jpg" alt="Developer Diane coding on her laptop.">
<figcaption>Developer Diane coding on her laptop.</figcaption>
</figure>
<p id="bio">Developer Diane is a graduate of Treehouse’s Front End Web Development Techdegree. She’s currently a junior developer at Super Web Design Shop.</p>
<h3>Other articles I’ve written</h3>
<nav>
<ul>
<li><a href="css-my-first-day.html">CSS: My first day</a></li>
<li><a href="css-learning-the-basics">CSS: Learning the basics</a></li>
<li><a href="css-selectors">CSS selectors!</a></li>
</ul>
</nav>
</aside>
<footer>©2020 Developer Diane.</footer>
</body>
</html>
If you're still experiencing issues, please create a snapshot of your Workspace and drop the link here for us to open up and play around with đź‘Ť