Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make one div float over another?

Tags:

html

css

I have two div elements on a page. How can I make one div to float over another just like a popup? In other words, div2 (the popup) would cover some part of the area of div1 (the parent).

like image 582
Firdous Avatar asked Sep 06 '11 13:09

Firdous


People also ask

How do I make a div float over another div?

Use position:absolute; and set the "popup" one to be positioned within the boundaries of the other. The "popup" div should likely also be smaller. Use z-index to stack the "popup" one above the other one (give it a higher value for z-index ).

How do I make a div appear 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.

How do you make a div appear in front of another?

Use the CSS z-index property. Elements with a greater z-index value are positioned in front of elements with smaller z-index values. Note that for this to work, you also need to set a position style ( position:absolute , position:relative , or position:fixed ) on both/all of the elements you want to order.


2 Answers

Use position:absolute; and set the "popup" one to be positioned within the boundaries of the other. The "popup" div should likely also be smaller.

Use z-index to stack the "popup" one above the other one (give it a higher value for z-index).

If you want to make it look like the inner div is really floating above the other one, create a shadow with something like border-right:2px solid black and border-bottom:2px solid black.

If you want to make it actually pop up/appear/disappear, you will need to use some script.

like image 158
yoozer8 Avatar answered Sep 26 '22 22:09

yoozer8


I believe setting the position to fixed will cause it to stay visible even if the user scrolls. You can set the position using "top", "left" and "right" attributes. The CSS I use for a "beta" logo which basically does what you are asking is this:

.fixed{     position:fixed;     top:0px;     right:0px;     width:100px; } 
like image 20
Mike_OBrien Avatar answered Sep 23 '22 22:09

Mike_OBrien