views:

295

answers:

4

Can you define an [if IE7] in the actual stylesheet? Or must you do it in the html to pull a different SS?

Thanks! (Google isn't being kind to me =/)

+2  A: 

You will have to do that in the HTML code. The only way to do such a thing directly in CSS is by using certain CSS-Selectors, which only IE7 recognizes. If I'm not mistaken, that would be

*+html #yourselector {}

for IE7.

x3ro
It's `* html` and then only for IE6.
BalusC
Yes, but he is asking for IE7, and for IE7 it is (I've checked) *+html
x3ro
I don't see it here: http://www.evotech.net/blog/2007/05/ie7-only-css-hacks-examples/
BalusC
But you can see it here: http://thatnorwegianguy.wordpress.com/2007/03/20/ie7-css-filter-hack/Linking to a page where it isn't listed is kind of a bad proof for non-existence ;)
x3ro
A: 

I think you can. http://www.conditional-css.com/

Joy Dutta
That's not CSS, that's a server-side script that modifies CSS on the fly. That's a whole different kettle of fish -- if you're going to be doing this server side, there are a lot of other ways to do it.
Daniel Pryden
Thanks for the correction !
Joy Dutta
A: 

You must do it in the HTML. There are various hacks to achieve similar behavior in CSS, but avoid them, as they may break in future browser versions.

Ishmael
+1  A: 

It has to be in the html. IE was able to work with CSS Expressions, but since it's entirely proprietary, and deprecated as of IE8, it won't, unless the browser is IE5-7, or running in compatibility mode with IE5 or 7, be executed/interpreted.

Plus, honestly, it's easier to use in the (x)html anyway.

Edited in response to the down vote and comments.

For use in the (x)html, conditional comments, not CSS Expressions, can be used to achieve the aims of selectively serving CSS (or other content) to IE browsers. CSS Expressions may, or may not, be able to achieve that (or similar) functionality in the stylesheet, but they are not a good idea. For many reasons, deprecation, and their being proprietary, being only two of them.

David Thomas
You will NOT want to use CSS Expressions ever. They will decrease your performance annoyingly, because they are evaluated _a lot_, that means every time you move your mouse, scroll, type, or do anything else on your page. I've seen a page with only 4 css expressions which had my dual core at more than 50% cpu, only by moving the mouse around.
x3ro
Check http://www.scottpetrovic.com/blog/2009/04/say-no-to-css-expressions-and-live-a-happier-life/ on why not to use CSS expressions.
x3ro
@ricebowl: Perhaps you meant **conditional comments** instead? http://www.quirksmode.org/css/condcom.html
Daniel Pryden
No, I meant what I said. I accept that they are a form of evil, and being a good *nix boy I never used them. But they were, for some, an option. I did not, however, mean to suggest that CSS Expressions were usable in the (x)html. That was a -bad- typo.
David Thomas
What´s with the strong **no against css expressions**? As far as I´m aware they are the only way to get for example transparent png's in IE6 so that makes them very useful for the time being.
jeroen
@ricebowl: I can see some convenience in the OP's question: it can be easier to conditionally include an IE only style-sheet once in the main css file instead of including it in every (x)html page that uses that main css file.
jeroen
@Jeroen, *everything* has its place. But I prefer not to use them. This is partially because even MS have deprecated them (as of IE8), and partially because it's practically JS in the wrong place. If you want to use the same effect, link all your pages -via whatever mechanism- to a js-script and it's just as easy, without polluting a stylesheet.
David Thomas
@ricebowl: That´s definitely true, I was just referring to your remark that it is easier in the (x)html. Anyway, as IE6 and 7 slowly disappear, so will the need for conditional comments and css expressions. For the time being I appreciate these little scripts that make IE6 almost behave like a decent browser :-)
jeroen
@Jeroen: That is not true. For that purpose, you have to use Microsoft's AlphaImageLoader, which, though proprietary, has nothing to do with CSS expressions at all.
x3ro