Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Always On Top [closed]

Tags:

html

css

image

I have a website with a fixed image at the top of my screen. When I scroll down my page the image stays at the top like it should. However, all content below overlaps my image and it is then covered.

How do I make my top bar (image) always stay on top? I want it to cover the content of the page as you scroll.

like image 247
user3130731 Avatar asked Jan 27 '14 16:01

user3130731


People also ask

How do I get a div above everything else?

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. in chrome.

How do I make a Div always stay on top?

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.


2 Answers

Ensure position is on your element and set the z-index to a value higher than the elements you want to cover.

element {     position: fixed;     z-index: 999; }  div {     position: relative;     z-index: 99; } 

It will probably require some more work than that but it's a start since you didn't post any code.

like image 105
Jared Eitnier Avatar answered Oct 01 '22 18:10

Jared Eitnier


Assuming that your markup looks like:

<div id="header" style="position: fixed;"></div> <div id="content" style="position: relative;"></div> 

Now both elements are positioned; in which case, the element at the bottom (in source order) will cover element above it (in source order).

Add a z-index on header; 1 should be sufficient.

like image 31
Salman A Avatar answered Oct 01 '22 16:10

Salman A