tags:

views:

46

answers:

4

in a CSS file, is there a way to give a specific height for a DIV that only applies on IE ONLY, and at the same time, give that same DIV another height that applies to all browsers except for IE ? thank you so much in advance ...

A: 

Create 2 css files, one for IE and one for the other browsers

Load the css file according to the browser like described here

Pere Villega
thank you for your reply, but I don't want to create another CSS file, I need the height property inside the same CSS file, I tried both hacks here, but non of them worked, because I use IE8 !! I need a way (or hack) to separate some IE CSS properties (like height) inside ONE SINGLE CSS file but not seprate files, as I exactly asked above
unprecedented
+2  A: 

You can create an IE-specific stylesheet and use IE Conditional statements.

<!--[if IE]>
<link rel="stylesheet" type="text/css" href="iespecific.css" />
<![endif]-->

This way, you basically have two stylesheets; one for IE and other for rest of the standard-compliant browsers.

Hacks could have been used such as:

_height:500px;
*height:500px;

But that is not recommended.

See Also:

Sarfraz
thank you for your reply, but I don't want to create another CSS file, I need the height property inside the same CSS file, I tried both hacks here, but non of them worked, because I use IE8 !! the tutorial you refered to was great, but it's all about importing specific CSS files not separating some CSS properties from specific browsers inside ONE SINGLE CSS file, as I exactly asked above
unprecedented
@unprecedented: Why you don't want to use two? Did you know it is good practice and better than using hacks. Also this is the way suggested by experienced folks out there.
Sarfraz
I do not need to create a whole css file just for a single height property, it's a big system and we do not want to increase the number of files created.
unprecedented
A: 

try this

<style>
    #mydiv { height:800px; }
</style>
<!--[if IE]>
<style>
    #mydiv { height:500px; }
</style>
<![endif]-->
Starx
Im sorry it did not work :( (p.s. Im testing on IE8)
unprecedented
This is not possible. Check this http://jsfiddle.net/z4Smy/ tested on ie6, ie8, ff3, safari, opera works
Starx
oops i thought I should put this code inside the css file itself, forgive me ...
unprecedented
thank you for your help, I used this method to solve the problem from inside the html file (not from the css file)
unprecedented
glad I could help
Starx
+1  A: 

I have used the following and it worked in IE8. Put the following code within tag.

You can watch the online version from here, http://nazmulweb.com/site5/demo/iecss/

    <style type="text/css">
    #tgtDiv
    {
        height: 300px;
        width: 400px;
        border: 1px solid green;
    }
    </style>

     <!--[if IE]> 
         <style type="text/css">

     #tgtDiv
    {
        height: 300px;
        width: 400px;
        border: 5px solid red;
    }
    </style>
    <![endif]-->
Hoque
thank you very much for your help
unprecedented