views:

37

answers:

2

I am trying to line up the top border of a content div with the bottom borders of an <li> list used for navigation right above (like a tabbed pane). In IE the alignment (or the margin I set) is off by 1 pixel.

Is there any way, directly within the css so that I don't have to create a separate IE stylesheet, to put a condition that will set the margin to IE's liking? OR, if the issue I'm having with IE being off by 1 pixel jumps out at you I'd love to hear why so that I can avoid the IE hack altogether (I know I haven't posted any code yet). Thanks!

+3  A: 

Yes, there is.

.myclass { *margin: 1px; }

This works for IE6 and IE7, do you need a hack for any other specific version?

Sergey Ilinsky
this worked great (for IE7 too). thanks
aeq
I haven't tested this in IE8, but a hack for that version would be great too
aeq
@aeq: So show Sergey some love and accept his answer already.
Robusto
I will once the site allows me to accept it
aeq
+1  A: 

Sergey is correct with that CSS hack, check this page out to see why it works. http://www.webdevout.net/css-hacks

Also, try this, It's more of a 2 part setup and involves a bit of markup, but is (in my opinion) cleaner and more flexible than CSS hacks and IE only stylesheets.

In the HTML, add an extra div (a few for each version of IE you want to target)

<body>
<!--[if IE 6]> <div class="IE6"> <![endif]-->
<!--[if IE 7]> <div class="IE7"> <![endif]-->
...
<!--[if IE 7]> </div> <![endif]-->
<!--[if IE 6]> </div> <![endif]-->
</body>

Then in your stylesheets, you can add classes inline to target the IE versions.

.className { ... some styles ... }
.IE6 .className { ... some styles to fix IE6 only ... }
.IE7 .className { ... some styles to fix IE7 only ... }

It's a bit of a twist on the conditionally stylesheets, only conditional styles.

cburyta
You have 2 `<!--[if IE 6]> </div> <![endif]-->`... did you mean one for `IE 6` and another for `IE 7`?
Hristo
Yeah, good catch, I did mean to have 2 different closing IE if statements for the divs. And... updated.
cburyta