I am new in CSS so please help me in this problem. I hope to describe it wright.
I am making div named content where my site content is. I made it with z-index:-1; so an image to be over this div. But in Chrome, FF and safari, content became inactive. I cant select text , click on link and write in the forms. So I tried with positive states in the z-index but IE don’t know what this means. Damn. So I decided to make conditional div. Here is the code:
.content
{
background:#FFF;
width:990px;
position:relative;
float:left;
top:50px;
}
.content_IE
{
background:#FFF;
width:990px;
position:relative;
float:left;
top: 50px;
z-index:-1;
}
and here is the HTML:
<!--[if IE 7]>
<div class="content_IE" style="height:750px;">
<![endif]-->
<div class="content" style="height:550px;">
Everything is fine with the z-index but the problem is that if there is no top in .content class everything looks fine in IE but there is no space in the other browsers. If i put back the top:50px; there onother 50px like padding in the .content_IE class. I mean that the page looks like I’ve put top:50px; and padding-top=50px;. I’ve try everything like margin-top:-50px; padding-top:-50px; and stuff like this but I am still in the circle. It look fine only if there is no top option in .content class. Please help.
The problem is that the two
divs aren’t mutually exclusive – IE’s seeing both of your .content and .content_IE divs, and the positioning that you’re trying to set is being governed by the interior .content div (because both haveposition: relativeapplied to them). Try removing the .content div from your code and look at it in IE, you’ll likely see the same issues you’re having in the other browsers. (For more information, this article covers positioning pretty well)(this is perhaps a bit verbose, but it provides some reasonable strategies for preventing this sort of issue in the future):
There are a few things going on here: IE-specific handling, and z-index issues.
First, a few style/strategy recommendations:
For the IE-specific declarations, a better approach is to set up your styles so that you can take care of the Cascade – set the base styles (height, width, etc) on the .content class, and then apply a few IE specific rules (like the different height). It would look something like this:
That way you should experience a) less potential weirdness, and b) an easier time maintaining your code. If your stylesheets are large enough, break up the rules in to two (like “main.css” and “ie7.css”, and link to the IE one from inside of the conditional comment.
Now, as far as the z-index issue goes – I would recommend applying the z-index on the image that you’re trying to place ‘on top’ of the content, and use a positive value. This should prevent some of what I believe you’re seeing happen in IE (IE tends to have issues with negative values in general, so try to avoid them if you can).
If that fixes the problem, keep working with your code so that you don’t need the conditional CSS, too.