Skip to content
Advertisement

How to get a Sticky header on website using Javascript?

Tried to get a sticky header onto my website using javascript, but doesn’t seem to be working.

Here is the html code and javascript related to this section:

JavaScript

Here is the CSS related to the sticky header:

JavaScript

Please help!

Advertisement

Answer

Step 1. Use header.sticky instead of header .sticky (remove space)

Step 2. Add the following style to header.sticky

JavaScript

How TO – Sticky Element

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement