Relative positioning, div stacking issue in ie 7 - html

This is my example code which is not working as expected in IE7 - I think position:relative; is the issue for IE7
.oner {
position:relative;
height:50px;
background:#fff;
border:5px solid #e4e4e4;
height:200px;
margin-top:20px;
}
.onea {
position:absolute;
height:500px;
right:0;
width:200px;
background: #eee;
z-index:999;
}
.onet {
position:absolute;
height:500px;
left:0;
width:200px;
background:red;
z-index:999;
}
HTML:
<div style="height:500px;width:900px;margin:auto;">
<div class="oner">
<div class="onea">IE IE7 this div goes behind the "oner" div below </div>
</div>
<div class="oner">
<div class="onet">My name is Sumit Kumar Ray my email is ..</div>
</div>
</div>
What happens is that the onea div goes behind the following oner div, but in other browsers it overlays it

setting a z-index on a div is actually supposed to create a stacking context, not simply bring the div, it's applied to, above another.. so while I do think IE7 didn't get it quite right, (surprise!)
I think it would be better to make the oner divs the ones that create the start of the stack by setting the z-index on them, and what you want it for the first oner to have a higher z-index than the second
<div style="height:500px;width:900px;margin:auto;">
<div class="oner" style="z-index: 1;">
<div class="onea">IE IE7 this div goes behind the "oner" div below </div>
</div>
<div class="oner">
<div class="onet">My name is Sumit Kumar Ray my email is ..</div>
</div>
</div>
with this there is no need for the Absolutely Positioned children to have a z-index at all, as those divs now take their "z level" from their relatively positioned parent - IE and the stack can be quite confusing!
CSS:
.oner {
position:relative;
height:50px;
background:#fff;
border:5px solid #e4e4e4;
height:200px;
margin-top:20px;
}
.onea {
position:absolute;
height:500px;
right:0;
width:200px;
background: #eee;
}
.onet {
position:absolute;
height:500px;
left:0;
width:200px;
background:red;
}
However it does mean that if you have more than two as in this example you need to set the levels on all the oner divs with the first one being the highest.. (that's why I put the oner style inline in the HTML if you have more you might need some more classes to separate them)

Since both the inner divs have a zindex of 999 the second should overlay the first, although zindex results can be unpredictable across browsers. Really you should set different zindex values to accurately control depth.

Related

Z-Index Not Working For Relative Divs

I have divs that have a background image, and I set them to be positioned relative with a high z-index. There are four of them and they should be seen under good examples here. However, they do not show up in the document, my guess because of a stacking issue
My HTML code
<div id="white_house" class="ext_image"><div class="view_site"></div></div>
<div id="abc" class="ext_image"><div class="view_site"></div></div>
<div id="quartz" class="ext_image"><div class="view_site"></div></div>
<div id="usatoday" class="ext_image"><div class="view_site"></div></div>
CSS (only one id is shown but same general style applies)
#ext_image {
position:relative;
z-index:5000;
}
#white_house{
width:490px;
height:231px;
background:url('http://webmaster.tsaprotectandserve.com/new_design/images/white_house_website.PNG') no-repeat center;
background-size:100%;
float:left;
margin-bottom:20px;
position:relative;
z-index:5000;
}

Centering and positioning elements within a centered, fixed position div/overlay-box

I am trying to position elements centrally, and in other positions within a fixed, centered box which overlays (when the user scrolls, the overlay-box stays put) my whole mobile site.
I have attached an image diagram to demonstrate what i'm trying to achieve:
Extra details include:
The 'overlay' has a width & height dependent upon the width and height of the users mobile device. i.e, width:80%; height:60%;.
I would like for the image in the top right hand corner of the diagram to always be that way on my site (as far in that corner as possible).
Any help is greatly appreciated. Cheers.
Check out the code. This mostly requires the use of relative and absolute positioning. You can tweak a bit to meet your needs
HTML
<div class="body" style="position:relative">
<div class="box">
<div class="box1"></div>
<div style="clear:both;height:20px"></div>
<div class="child"></div>
<div style="clear:both;height:20px"></div>
<div class="child"></div>
</div>
</div>​
CSS
.body{
width:400px;
height:250px;
background-color:#888;
}
.box{
width:80%;
height:150px;
border:1px solid #FFF;
position:relative;
margin:auto;
top:10%;
}
.child {
height:10px;
width:50px;
position:relative;
margin:auto;
background-color:red;
}
.box1{
width:10%;
height:10%;
border:1px solid #FFF;
position:absolute;
top:0;
right:0;
}
​
I have added the fiddle too. http://jsfiddle.net/nQvEW/176/

CSS Box-Shadow div overlay

I have a problem with a box-shadow, being obscured by another div.
Here is my code:
HTML-
<div id="wrap">
<div id="header">
<div id="nav"></div>
</div>
<div id="main_content"></div>
<div id="footer"></div>
</div>
CSS-
body{
margin:0;
}
#wrap{
margin:0 auto;
width:84%;
}
#header{
background-image:url(img/header_pattern.png);
background-repeat:repeat;
margin:0 auto;
width:100%;
height:170px;
box-shadow:5px 5px 5px black;
z-index:1;
}
#main_content{
background-image:url(img/main_pattern.png);
background-repeat:repeat;
width:100%;
min-height:700px;
height:100%;
z-index:2;
}
Screenshot-
http://i.stack.imgur.com/TfDyi.png
How can I make it so that the shadow is not "stacked under" (on the z-axis), and hence obscured by, the #main_content div, but still inside my #wrap?
Thanks.
No, I don't just wan't to push the #main_content down.
Just add:
position: relative;
To #header{
Example:
http://jsfiddle.net/kJajC/
You need to "position" an element, if you want to "stack" it differently on the z-axis using z-index.
Note that if you don't actually want to change its position on the x/y plane, then just specify that it is position:relative; without any of the top, bottom, left or right x/y offsets and it'll be positioned on the x/y plane where it would've been laid down statically anyway.
From MDN on adding a z-index:
Warning! z-index only has an effect if an element is positioned.
I found their series of articles Understanding CSS z-index really helpful with this stuff.

Cannot Select Text Inside Z-Index/Position Div

I am trying to create a website where I have several divs positioned in-front of a background div by using z-index and position:absolute. This background div will be transformed later into a content carousel so it is vital that its text are selectable. My current code does not allow for the text and link to be selected and I am wondering how would I fix this.
http://jsfiddle.net/6fwf9/2/
HTML:
<div id="header" class="box">header</div>
<div id="bg">
Cannot highlight this text <br>
Cannot click on this link
</div>
<div class="box">content</div>​
CSS:
.box { width: 150px; height:50px; background:aqua; margin:20px; }
#header { margin-bottom: 150px; }
#bg { width:200px; height:200px; padding-top:100px; background:pink;
position:absolute; top:0; z-index:-10;}​
EDIT - Image of what I am trying to achieve: http://imgur.com/r9tYx
Make sure the overlaid elements (.box) don't sit in front of the text content, if they are to be selectable. That means positioning them some other way than by using margins. This example works because the boxes uses absolute positioning: http://jsfiddle.net/2pPKz/
Alternatively, if the background is to become a carousel, couldn't you worry about it when it's actually a carousel, and move it to the front then?
I just saw your picture, This is how I would do it.
<div id="bg">
<div id="container">
Cannot highlight this text
<br>
Cannot click on this link
</div>
</div>
<div id="header" class="box">header</div>
<div class="box">content</div>
And for the CSS, Please take notes that I put border around the container to show where it is and what is the width and height
.box{
width:150px;
height:150px;
z-index:2;
position:absolute;
background: cyan;
top:150px;
left:20px;
}
#bg{
background-color:pink;
width:200px;
height:170px;
position:absolute;
top:0px;
}
#header{
position:absolute;
width:150px;
height:50px;
left:20px;
top:20px;
z-index:2;
background: cyan;
}
#container{
width:100%;
position:relative;
border:1px solid black;
margin-top:100px;
}
The only thing left is you play with your dimention.
Actualy I put everything absolute exept the container.
It is because the bottom margin of the Header is over the text. I sugest you to change the way you are doing things here. Why don't you just make elements be inside the bg box?
<div id="bg">
<div id="header" class="box">header</div>
<p>Cannot highlight this text Cannot click on this link</p>
<div class="box">content</div>​
</div>
With static position? Even if you want to use absolute positioning, you could have everything inside the bg div and have it with position:relative, so the elements inside will be positioned absolutely respected to it.
Unfortunately the only way to do what you're trying to do is to split up the background and the text content for the slider.
That means each slide would need to consist of a background div that is absolutely positioned behind the content, and a content div that is absolutely positioned in front of everything else.

Overlapping issue

I am having an issue with overlapping items within a floating div. I must be applying the z-index wrong, but I've tried a few different things and I can't get the two items to overlap. I have the following code (note: topLink and topIconNew divs are actually pngs):
http://jsfiddle.net/jhacks/neskB/7/
HTML:
<div class="topIcon">
<div class="topIconNew"></div>
<div class="topLink"></div>
</div>
CSS:
.topIcon{
border:1px solid black;
background-color:gray;
width:28px;
height:40px;
float:right;
position:relative;
}
.topLink{
background-color:green;
width:16px;
height:16px;
position:absolute;
top:14px;
left:6px;
z-index;300;
}
.topIconNew{
background-color:red;
margin:30px 0px 0px 18px;
width:10px;
height:10px;
position:relative;
z-index:350;
cursor:pointer;
}
The HTML for the pngs (if it makes a difference):
<img src="xxxxx.png"> </img>
EDIT** I've done it! Finally. Thank you for the help... upon seeing your code I saw the use of absolute and relative together. I now have a better understanding over the usage of those things and now instead of positioning things with padding/margins, I'm using (and correctly so I'd assume) positioning. I feel stupid for doing what I was doing.
Thanks for the edits, your question is much more clear now. I think this will satisfy your question.
http://jsfiddle.net/neskB/26/
Okay, so this makes a lot more sense now.
You have gray div floated right
You want to center a green div in this
You want a red div in bottom right of green div
First I would change your html structure to this.
<div class="topIcon">
<div class="topLink">
<div class="topIconNew"></div>
</div>
</div>
Link will be positioned relative to its parent Icon.
New will be positioned relative to its parent, Link.
/* set topIcon to relative so that its child will be positioned relative to it */
.topIcon{ position: relative; }
/* topLink is absolute positioned. We use top/left of 50% and negative margins to automatically center it */
.topLink{
position: absolute;
width:16px;
height:16px;
margin:-8px 0 0 -8px;
left:50%;
top:50%;
}
/* New is positioned in bottom right of its parent */
.topIconNew{
position:absolute;
bottom:0px;
right:0px;
}