Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Float a div above page content

Tags:

css

z-index

I've implemented a popup box that dynamically displays search options. I want the box to "float" above all of the site content. Currently, when the box is displayed it displaces all of the content below it and looks bad.

I believe I've already tried setting the z-index of the box's div to above that of the remaining page content, but still no luck.

like image 405
Eric Di Bari Avatar asked Jan 05 '10 13:01

Eric Di Bari


People also ask

How do I make a div float on top of another CSS?

Answer: Use the CSS z-index Property You can use the CSS position property in combination with the z-index property to overlay an individual div over another div element.

How do I keep a div at the top of the page?

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 float in HTML?

Use CSS property to set the height and width of div and use display property to place div in side-by-side format. float:left; This property is used for those elements(div) that will float on left side. float:right; This property is used for those elements(div) that will float on right side.


2 Answers

You want to use absolute positioning.

An absolute position element is positioned relative to the first parent element that has a position other than static. If no such element is found, the containing block is html

For instance :

.yourDiv{   position:absolute;   top: 123px; } 

To get it to work, the parent needs to be relative (position:relative)

In your case this should do the trick:

.suggestionsBox{position:absolute; top:40px;} #specific_locations_add{position:relative;} 
like image 62
marcgg Avatar answered Sep 20 '22 15:09

marcgg


Use

position: absolute; top: ...px; left: ...px; 

To position the div. Make sure it doesn't have a parent tag with position: relative;

like image 38
Jimmy Shelter Avatar answered Sep 18 '22 15:09

Jimmy Shelter