0

What are the different ways of writing css hacks for ie?

I have seen html >, *.. but it is all very confusing..

Are there hacks to target specific ie versions like ie7, ie8 ?

Kara
  • 5,650
  • 15
  • 48
  • 55
testndtv
  • 43,898
  • 91
  • 265
  • 396

2 Answers2

2

I would recommend splitting IE "hacks" into a separate stylesheet so than can be dropped in the future as support for those browsers is dropped.

With this approach, you can use conditional comments to add the appropriate stylesheet for the appropriate version on IE.

Here's a good post on conditional comments: http://css-tricks.com/132-how-to-create-an-ie-only-stylesheet/

Phillip Burch
  • 459
  • 5
  • 11
  • In my experience, separate CSS stylesheets are not maintained as the primary stylesheet is modified. CSS hacks are way better in this regard. – Arnaud Le Blanc Aug 22 '11 at 17:40
  • That's not so much my experience, but http://lesscss.org/ may help mitigate some of that. However, if you really want it all in one stylesheet, it would be better to the append a css class to the body tag that has the name of the browser than muddy up the css with all these hacks. – Phillip Burch Aug 22 '11 at 17:46
  • This is an other very bad trick actually. Prefixing a css rule with a class gives more specificity to it. That means that a rule in `.ie6 #menu` can't be overrident by a **later** rule `#menu` without the `.ie6` prefix (`#menu{color:black;}.ie6 #menu{color:red;} #menu{color:black; /* menu is still red in ie6, beware of bugs! */}`. See http://dev1.slideshare.com/stubbornella/css-bloat slide 61. – Arnaud Le Blanc Aug 22 '11 at 17:53
  • not so much a bad trick. The question about the best way to hack something. Did you really expect a perfect solution? – Phillip Burch Aug 22 '11 at 18:05
  • Also, the behavior that you're referring to in my opinion would be desired behavior. It's very clear to another developer who comes along exactly what the code is doing. There are also tons of other benefits to those class names. – Phillip Burch Aug 22 '11 at 18:12
1

There plenty of such topics. But to be constructive, here is the topic of IE CSS hacks explained (below conditional statements).

mkk
  • 7,275
  • 7
  • 41
  • 62