Early on in web development we were encouraged to use browser detection scripts to feed css or javascript to supporting browsers.
Then that became a no no, it was better to detect functionality support in browsers before using the scripts or use css hacks to give styles to the correct browsers.
Now it looks as if we are moving in another direction with IE7 on it's way.
The Internet Explorer blog is encouraging the use of conditional comments to stop our sites, hacked to work in IE <=6 falling over in IE7.
Conditional comments have been something I have avoided using mainly because they are Microsoft proprietary elements. If they were supported by all browsers, not just ignored by them, they may have been useful. Even better would have been a similar CSS Conditional Comment.
Here's a list of CSS hacks that could cause problems in IE7:
- html > body - http://css-discuss.incutio.com/?page=ChildHack
- * html - http://css-discuss.incutio.com/?page=StarHtmlHack
- head:first-child + body - http://centricle.com/ref/css/filters/tests/owen/
- head + body - http://www.dithered.com/css_filters/css_only/head_adjacent_sibling_body.html
- body > element - http://css-discuss.incutio.com/?page=ChildHack
Conditional Comments
Looking at my own use of hacks, I see nearly all are either the star hack or child selector. Related to this,
- IE7 will cure most if not all of the hasLayout dependent bugs—Big John's list.
I do foresee problems if MS doesn't fix something that needs, say, the Holly hack. In that case we will have to use conditional comments. I don't like the idea of proprietary markup, but don't see an alternative. I understand if they can't bring IE completely up to date, I just want them to make what they do support work correctly.
cheers,
gary
[/]Conditional Comments
Like Gary I tend to use very few hacks and when I do they are chiefly star selector and Child.
So if the problems that the Star selector addresses are cleared up and the Star selector ignored in IE7 I don't see major problems despite the alarmist warnings that the Star selector is deprecated, do not use[css-discuss].
The problems seem to be with the fact that MS are still going to preserve white space for empty elements ( but they were the first to implement this and so are right!) whilst the W3C says empty elements should be ignored. So the problem arises as demonstrated on the MSDN Blog where a child selector is used to feed normal margins and then a second rule set feeds a negative margin to compensate for IE white space. This hack now falls apart as IE7 reads the child selector.
There is no apparent way now of hacking this that I have been able to see, other than as said to have to pull the rule out and wrap it in MS conditional comments; so we now have a second stylesheet or extra bulk in the header of each page, not ideal.
I'm no lover of hacks and seem to manage with surprisingly few by being carful and not using them to correct bad use of CSS properties, but whilst there are these sorts of major differences in the way IE treats certain aspects of rendering I would feel happier knowing that I still had something to use.
Hugo.
clearfix and IE7
I'm left wondering... Tony's clearfix method on IE relies on the "auto-clearing" of floats, that is, a violation of the spec. So, what if this is fixed on IE7, AND they don't add after support?
(Or is this just one of the countless compatibility questions that will remain unanswered until IE7 beta 2?)
Conditional Comments
Hi manuelrazzari,
That is an interesting question.
The technique will continue to work on current browsers but may need to be modified or hidden from IE7.
We will have to wait and see what IE7 brings us.
Re: Conditional Comments
Conditional comments have been something I have avoided using mainly because they are Microsoft proprietary elements.
True, but they can be masked as comments. So they won´t cause problems in other browsers.
If they were supported by all browsers, not just ignored by them, they may have been useful. Even better would have been a similar CSS Conditional Comment.
Most definitely. Though I fear that a consistend HTML-way of detecting the browser would lead to the construction of multiple html pages, instead of merely "correcting" the existing one.
I personally prefer CC - I think it´s a cleaner way to use something that acts like comments, instead of hoping that only one browser misunderstands certain elements.
Re: clearfix and IE7
I'm left wondering... Tony's clearfix method on IE relies on the "auto-clearing" of floats, that is, a violation of the spec. So, what if this is fixed on IE7, AND they don't add :after support?
(Or is this just one of the countless compatibility questions that will remain unanswered until IE7 beta 2?)
I believe, IE7 claims they will support the :after selector.
Hugo seems to have correctly identified the main problem. IE7 seem to have shown a commitment to remove IE6 bugs and to give as good a support for CSS2.1 selectors as any browser. If that is the case, the problem will be where the IE7 team is happy to implement what they consider a compliant behaviour but in a different manner from the method chosen by other compliant browsers.
Re: Conditional Comments
I personally prefer CC - I think it´s a cleaner way to use something that acts like comments, instead of hoping that only one browser misunderstands certain elements.
Yes. It would be good if other browsers supported it too. Although it probably would never make it into the standard its a real life concession that sometimes different browsers may behave differently.
Only problem would be, some browsers would then decide they should handle another browsers CCs.
Conditional Comments
I think all sorts of nightmare scenarios would develope if everyone started to implement their own conditional comments you might as well be coding completely separate stylesheets.
Chris's statement "where the IE7 team is happy to implement what they consider a compliant behavior but in a different manner from the method chosen by other compliant browsers." is the crux of the problem as MS clearly still think that they are right on certain aspects and that the W3C are wrong and thus do they still demonstrate the desire to not comply fully with a unified standard; the white space issue is a case in point where MS clearly state that they were first to implement this behavior of honouring white space for empty elements and seemingly are not going to consider complying with the perceived standard, creating a new set of problems in their desire to be seen to fix up CSS support. They are a funny lot.
Hugo.
Conditional Comments
This discussion seems to be inbetween a whole load of pro's, so sorry if i join.
I just learned about the * html hack today which i need for one element's width which is not rendering as desired in IE6.
So, am i right or wrong in understanding that IE7 will ignore this and render it just as FF and NS are and that there is nothing to worry about?
Conditional Comments
So, am i right or wrong in understanding that IE7 will ignore this and render it just as FF and NS are and that there is nothing to worry about?
Pretty much yes. I don't know that any of us here has seen IE7, but the IE7 blog is written by people close to/involved in IE7 development and it claims as much.
To explain a little.
* html someselector, while syntactically correct, is invalid in the (X)HTML context. html is the root element so can not be descended from any other element. This "bug" with IE6 and earlier versions is one of those identified as to be (been?) fixed in IE7.
Conditional Comments
Thanks for clearing that up.
Now, wouldn't it be nice if MS .... ?
Put a nice little option on the install dialog.
If you would rather have a reliable and solid browser don't click I Accept and don't install, instead, GET FIREFOX!
Trevor
Re: Now, wouldn't it be nice if MS .... ?
Put a nice little option on the install dialog.
If you would rather have a reliable and solid browser don't click I Accept and don't install, instead, GET FIREFOX!
Trevor
You're a clever one. Are you by chance related to Magical Trevor?