Overlaying DIVs

dejo

Moderator
Original poster
Staff member
Sep 2, 2004
15,981
447
The Centennial State
The Question: How do I get Overlay #1 to overlap the green, right-side the same way that Overlay #2 overlaps the red, left-side? Overlay #1 must be "tied-to" the left-side DIV, so that wherever the red area goes, Overlay #1 goes with it.

The Page:
Overlay Test

The Screenshot:


The Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<title>Float Test</title>
<style type="text/css">
body {
font-family: Verdana;
}
#container {
background-color: blue;
width: 450px;
height: 220px;
padding: 10px;
}
#left_side {
background-color: red;
width: 180px;
height: 200px;
padding: 10px;
float: left;
position: relative;
}
#right_side {
background-color: green;
width: 180px;
height: 200px;
padding: 10px;
float: right;
position: relative;
}
#overlay_box_1 {
background-color: yellow;
width: 200px;
height: 50px;
position: absolute;
top: 0px;
left: 100px;
opacity: 0.8;
}
#overlay_box_2 {
background-color: yellow;
width: 200px;
height: 50px;
position: absolute;
bottom: 0px;
right: 100px;
opacity: 0.8;
}
</style>
</head>
<body>
<div id="container">
<div id="left_side">LEFT LEFT LEFT LEFT LEFT LEFT LEFT LEFT LEFT LEFT
<div id="overlay_box_1">OVERLAY #1</div>
</div>
<div id="right_side">RIGHT RIGHT RIGHT RIGHT RIGHT RIGHT RIGHT RIGHT RIGHT RIGHT
<div id="overlay_box_2">OVERLAY #2</div>
</div>
</div>
</body>
</html>
P.S. My apologies to anyone who's red-green color blind.
 

cookie1105

macrumors 6502
Mar 27, 2006
426
0
London, UK
I hope this helps you:

I added z-index and changed left position to 150px for #overlay_box_1

Code:
#overlay_box_1 {
background-color: yellow;
width: 200px;
height: 50px;
position: absolute;
top: 0px;
[COLOR="Red"]left: 150px;[/COLOR]
opacity: 0.8;
[COLOR="Red"]z-index: 99;[/COLOR]
}
Here is how it looks:
 

Attachments

dejo

Moderator
Original poster
Staff member
Sep 2, 2004
15,981
447
The Centennial State
cookie1105 said:
I hope this helps you:

I added z-index and changed left position to 150px for #overlay_box_1

Code:
#overlay_box_1 {
background-color: yellow;
width: 200px;
height: 50px;
position: absolute;
top: 0px;
[COLOR="Red"]left: 150px;[/COLOR]
opacity: 0.8;
[COLOR="Red"]z-index: 99;[/COLOR]
}
Here is how it looks:
Thanks for the help. The z-index manipulation does the trick, except for in Internet Explorer. Grr... :mad: