Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A DIV that stays at the top while a web page scrolls

How would I have a DIV stay at the top of the page visually as the user scrolls down a web page?

A simple Javascript framework would be great!

it's for this web site: http://BiblePro.BibleOcean.com

like image 698
Ian Vink Avatar asked Oct 10 '09 18:10

Ian Vink


People also ask

How do you make a div stay at the top of the page when scrolling?

The vertical position of the element to be stuck can also be modified with the help of the 'top' property. It can be given a value of '0px' to make the element leave no space from the top of the viewport, or increased further to leave space from the top of the viewport.

How do you make a div fixed position while scrolling CSS?

To make div fixed scrolling to that div with CSS, we can use the position: sticky CSS property. position: -webkit-sticky; position: sticky; top: 0; z-index: 1; to set position to sticky and z-index to 1 to make the element with the sticky position show on top after we scroll to it.

How do I make div stay on top of another div?

You can use the CSS position property in combination with the z-index property to overlay an individual div over another div element. The z-index property determines the stacking order for positioned elements (i.e. elements whose position value is one of absolute , fixed , or relative ).

How do I make a div appear on top of everything?

Set the DIV's z-index to one larger than the other DIVs. You'll also need to make sure the DIV has a position other than static set on it, too. position relative and z index set to 999999999999999999999999999999999999999999999999999.


1 Answers

If you don't care about IE6, you can use position: fixed:

div {   top: 0;   position: fixed } 

Using jQuery, see this question: What is the simplest jQuery way to have a ‘position:fixed’ (always at top) div?

like image 138
Kobi Avatar answered Oct 02 '22 15:10

Kobi