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

JavaScript Using jQuery Plugins Add a Sticky Navigation Bar The Plugin Challenge Solution

yashita mittal
yashita mittal
4,678 Points

Content overlaps the sticky h5 tag

When I stick the content in h5 tag to the top, the bottom content seems to move over the work line in h5 tag.

main.js:

$(".grid-full h5").sticky({
    topSpacing:60,
    getWidthFrom: '.container',
        responsiveWidth: true
});

I have added the following code in css file to make the background colour white, but it doesn't work.

.is-sticky .grid-full h5 {
    background-color: white;    
}

When I change the background-color to black, then it works fine. The content smoothly moves under the sticky h5 tag. I am not able to understand why white color does not work?

1 Answer

Chris Shaw
Chris Shaw
26,676 Points

Hi yashita mittal,

First and foremost, I recommend you read Posting Code to the Forum to ensure your formatting is correct :smile:.

When sticking elements on a page in a fixed position we need to account for the source order of sibling elements which will hold a higher Z value compared to the previous element, we can overcome this by setting a z-index property in our CSS which will bring the sticky element above all other content preventing any unwanted overlapping.

.is-sticky .grid-full h5 {
  background-color: white;

  /* Arbitrary Z value to ensure it sits above all other content */
  z-index: 10;
}

Happy coding!