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 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,606 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;"