Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

CSS CSS Layout CSS Layout Techniques Fixed and Sticky Positioning

Cory Rhodes
Cory Rhodes
5,096 Points

Can't get my "sticky" to work.

CSS:

  • { box-sizing: border-box; } header { padding: 15px 10px; } #verdict { margin: 0px; } #logo { border: 8px solid orange; background-color: blue; color: gold; margin: auto; width: 100%; left: 0; top: 0; font-size: 1.75rem; text-align: center; position: sticky;

} aside img, #bio { max-width: 600px; width: 100%; } .small-img { width: 100%; }

.figP { clear: both; right: -10px;

}

amazingBanner {

background-color: firebrick;
height: 15vh;
width: 100%;
margin: auto;
color: white;
font-size: 1.75rem;
align-content: center;
border: inset gold 3px;
text-align: center;
position: sticky;
top: 0px;

}

figure { position: relative; } figcaption { position: absolute; bottom: 20px; } section {

border-style: dotted;
margin-top: auto;
padding: 15px;
overflow: visible;
margin-bottom: 2px;

}

aside img { border: solid medium black; } aside p { width 600px; background-color: mistyrose; border-color: tomato; border-style: solid; margin-top: 15px; padding: 12px; } ul li { display: inline-block; background-color: yellow; padding: 6px; border-radius: 10px; border: inline 2px black; text-align: center; } a:visited { color: seagreen; }

a:hover { text-decoration: underline; }

a:focus { color: white; background-color: orange; }

@media print { section: min-height: auto; } #interestingbanner { display: none; } @media screen and (min-width: 600px) {

.small-img {
    float: left;
    width: 300px;
    margin: 0rem 1rem 1rem 0rem;
}
.clear {
    clear: both
}

} @media screen and (min-width: 730px) { ul li { display: inline-block; width: 30%; } }

1 Answer

Tomas Schaffer
Tomas Schaffer
11,581 Points

change the amazingBanner position from sticky to fixed and leave the top: 0 as it is. Should do it. Also if you setting top 0 you can omit the px "postion: fixed; top: 0;"