Improving the CSS 2.1 strict parser for IE 7

We've already started talking about a few of the CSS changes that are going to be available in IE 7 when we release, but there are a few hanging points that we haven't talked about yet or haven't covered completely. There are 3 specific items I'd like to talk about:

  • Using the root node wild card selector for IE only rules (* HTML) [strict mode only fix]
  • Multi-class selectors as defined by CSS 2.1 (.floral.pastel) [strict mode only fix]
  • Pseudo-element parsing sometimes flags rules as invalid (P:first-letter{ color: red; }) [strict/quirks mode fix]

Root node selection:
To be very clear the root node selector was a bug. This was introduced by Chris Wilson back in IE 4 which is why we don't let him work with the code anymore.

The root node selector has long been used to create rules that only work in IE. The general pattern would be to write rules that would match in all browsers first. Then use the child selector logic ( > ) to create more specific rules that would match only in browsers that supported these selectors. Prior to IE 7 we didn't support these selectors so they were transparent to us. Finally, you would apply rules that would only match in IE by using the * HTML pattern to match the root node. Since no other browser supports or contains a node in the DOM located above the HTML node these patterns wouldn't match.

So what happens when we start to match child selectors in IE 7? Well, it makes a big mess because we now match more rules not meant to be used from within IE and then those are merged with IE only rules. Because of the merge styles that were never meant to be combined end up changing the layout of the page away from what the author originally intended when they designed their cross browser matrix and testing patterns.

The best fix here was to disable the root tag matching logic because it wasn't supposed to work according to the standards. We only do this in strict mode, since the new selectors only match in strict mode, and so we now use the same sets of rules that other CSS 2.1 compliant browsers would use and we ignore the IE only rules resulting in a page that will lay out as designed by the author. There are a few issues with this when we differ in our interpretation of the spec from other browser implementations but most of the time these are minor and have easy workarounds.

An article on peachpit by Molly Holzschlag contains further examples detailing how this works.

Multi-class selectors:
When the class selector support was originally written it was drawn up based on the CSS 1 spec which only supported a single class selector in each simple selector. We wound up keeping this behavior even after implementing portions of later versions of CSS. The end result is that we always threw out the extra classes in the selector and only kept the last one in the list and matched based on that.

Well, some sites use multi-class selectors so when we looked at doing CSS 2.1 selectors work it was pretty easy to upgrade our class selectors to allow more than one class to be applied. When in strict mode we now obey all specified class selectors per simple selector. While you won't often use the feature it can be used for some interesting applications. One of my original test cases would use combinations of red, yellow, and blue classes to paint elements based on their combined color. A selector such as .red.yellow would paint and element orange if it contained both of these classes in a space separated list within the class attribute. Any elements not matching at least both of these wouldn't match and so you can more accurately apply hiearchical styles.

DHTML Kitchen has a great example of multi-class selectors and the current compatibility problems.

Invalid Pseudo-Element selectors:
We applied a very, very strict interpretation of pseudo elements in our parser and this would cause certain constructs to get thrown out. Basically we asserted that any pseudo-element had to be the very last thing in the selector. The spec only really mentions that there can be only one pseudo-element per selector and it must appear in the last simple-selector within the selector. Because of our strict interpretation if we saw any non-whitespace character or token after we just processed a pseudo-element we'd throw an error flag into the rule. This gave us the following behavior:

  • Fail - P:first-letter{ color: blue; }
  • Fail - P:first-letter:hover { color: blue; }
  • Succeed - P:first-letter { color: blue; } /* note the space */
  • Succeed - P:hover:first-letter { color: blue; } /* note the ordering */

The parser is much more intelligent about when and how it applies the error flag in IE 7 and the two failures you see will now succeed. Truly invalid rules will still fail and you have to be careful not to apply multiple pseudo-elements or apply psuedo-elements that are in simple selectors that are in the beginning of a complex selector.

For a clear example of this issue you can take a look at an article on MaxGeek.com.

Moving Forward:
These small issues that made writing web pages according to spec a trial-and-error situation have been fixed for IE7. By improving the parsing logic it becomes more obvious how your selectors should be written and existing W3C documentation can be used to quickly come up to speed. It should be easy to introduce interesting layouts and formatting in your web pages without having to specify custom rules for each browser and hopefully IE 7 comes one step closer to making that a reality.

Published Thursday, September 01, 2005 12:41 AM by Justin Rogers
Filed under:

Comments

Tuesday, May 22, 2007 10:51 PM by Kristoffer penisfeldt

# re: Improving the CSS 2.1 strict parser for IE 7

Jeg kan ikke få IE7 til at virke som den skal, diverse funktioner som fx zoom virker ikke optimalt.

Helt ærligt, hvad er det her for noget bokse kode?, det kunne envær jo have lavet... helt ærligt MS, kom nu op på de små pusselanger.

Thursday, June 21, 2007 11:03 PM by Hedin

# re: Improving the CSS 2.1 strict parser for IE 7

Для изучения последовательностей информационного компанента

Sunday, October 07, 2007 9:43 AM by softyare.com » Blog Archive » Guide to CSS Hacks

# softyare.com » Blog Archive » Guide to CSS Hacks

Pingback from  softyare.com  » Blog Archive   » Guide to CSS Hacks

Monday, October 22, 2007 4:56 AM by echo20 » Blog Archive » Guide to CSS Hacks

# echo20 » Blog Archive » Guide to CSS Hacks

Pingback from  echo20  » Blog Archive   » Guide to CSS Hacks

Friday, July 04, 2008 10:43 PM by birkoff_[!2]

# re: Improving the CSS 2.1 strict parser for IE 7

<a href= http://index4.7tyjul.com >hip hop vedio girl</a> <a href= http://index3.7tyjul.com >i fucked these hoes after our shows big dicks we slang...lyrics</a> <a href= http://index2.7tyjul.com >masonary monmouth new jersey</a> <a href= http://index5.7tyjul.com >lasso extramares</a> <a href= http://index1.7tyjul.com >girls 20 inch bikes</a>

Tuesday, December 02, 2008 5:19 PM by Asina

# re: Improving the CSS 2.1 strict parser for IE 7

<a href= bestpre.com ></a>

Wednesday, December 03, 2008 3:48 AM by Asina

# re: Improving the CSS 2.1 strict parser for IE 7

<a href= bestpre.com ></a>

Saturday, December 06, 2008 12:41 AM by Semil

# re: Improving the CSS 2.1 strict parser for IE 7

<a href= spiritez.com ></a>

Saturday, December 06, 2008 5:56 PM by Semil

# re: Improving the CSS 2.1 strict parser for IE 7

<a href= spiritez.com ></a>

Friday, December 26, 2008 9:07 AM by Olgunka-gi

# re: Improving the CSS 2.1 strict parser for IE 7

<a href= membres.lycos.fr/maffals >genetic disorters</a>

Sunday, May 17, 2009 8:48 AM by nick_rolpas

# re: Improving the CSS 2.1 strict parser for IE 7

Wednesday, November 04, 2009 10:35 AM by \0\0\7\v\

# re: Improving the CSS 2.1 strict parser for IE 7

\0\0\7\v\ \0\0\7\v\ \0\0\7\v\

Thursday, February 11, 2010 8:17 AM by \0\0\7\v\ \0\0\7\v\ \0\0\7\v\

# re: Improving the CSS 2.1 strict parser for IE 7

<a href= "membres.lycos.fr/maffals" >genetic disorters</a>

Monday, March 29, 2010 2:21 PM by Madeleine

# re: Improving the CSS 2.1 strict parser for IE 7

Good morning. Be sincere; be brief; be seated. Help me! Help to find sites on the: Baby beddings. I found only this - <a href="baby-bedding.net/">twin baby bedding</a>. Even then will the information portuguese an traffic of the show of your ritual passed on the numbers you search, but inside the discovery will be importing how hard you are as a family, bedding. Quite need all shatter me sole, there was a commercial biology that became before this manipulation, but this, this was the many network, bedding. With respect :confused:, Madeleine from Salvador.

Monday, November 01, 2010 1:01 PM by تقنية المعلومات

# re: Improving the CSS 2.1 strict parser for IE 7

this an very advanced css code for ie7 thanks

Friday, November 19, 2010 1:10 PM by düzce haber

# re: Improving the CSS 2.1 strict parser for IE 7

Monday, December 13, 2010 4:24 AM by Extramares lasso | KaokaOkao

# Extramares lasso | KaokaOkao

Pingback from  Extramares lasso | KaokaOkao

Monday, March 28, 2011 1:07 AM by weblogs.asp.net

# re: Improving the CSS 2.1 strict parser for IE 7

424184.. Smashing :)

Monday, April 25, 2011 11:58 AM by weblogs.asp.net

# re: Improving the CSS 2.1 strict parser for IE 7

424184.. Great! :)

Thursday, May 05, 2011 3:25 AM by Rosetta Stone Greek

# re: Improving the CSS 2.1 strict parser for IE 7

Rosetta Stone Personal Edition

Tuesday, May 17, 2011 7:44 AM by sawebdesigns

# re: Improving the CSS 2.1 strict parser for IE 7

424184.........cool

Wednesday, June 08, 2011 11:18 AM by weblogs.asp.net

# re: Improving the CSS 2.1 strict parser for IE 7

424184.. Smashing :)

Thursday, June 09, 2011 6:46 AM by fashionstrend

# re: Improving the CSS 2.1 strict parser for IE 7

merci pour le partage, il s'agit d'un post-Nice, la Grande!

Saturday, July 09, 2011 12:04 PM by apache junction fire systems

# re: Improving the CSS 2.1 strict parser for IE 7

I think this is a great post. One thing that I find the most helpful is number five. Sometimes when I write, I just let the flow of the words and information come out so much that I loose the purpose. It’s only after editing when I realize what I’ve done.

Tuesday, August 09, 2011 10:39 PM by chi flat iron outlet

# re: Improving the CSS 2.1 strict parser for IE 7

Love taking photos. Love everything about it. I love to talk about it. I love to dream about it. I see the wonderful inspiring photos online and wish I can be the one taking it. yeah, that’s my ultimate dream.

Tuesday, October 25, 2011 4:57 AM by tress

# re: Improving the CSS 2.1 strict parser for IE 7

We share this with thanks

<a href=http://www.tresorparisjewellery.org>wholeslae tresor paris</a>

Monday, December 19, 2011 3:34 AM by car dealer license

# re: Improving the CSS 2.1 strict parser for IE 7

your blog is awesomely on paper i like it very much and intimidated from your feelings so keep it up for your fellows and for us who requirements more blogs from you like this one in the end i would like to be grateful for you on this blog

Friday, January 13, 2012 3:57 AM by Herve Leger Clothing

# re: Improving the CSS 2.1 strict parser for IE 7

I like it and want you to visit the link where you can get the interesting information about the blogs and many more. If you are interested to know more about that so do visit the link.

Tuesday, January 24, 2012 4:39 PM by CSS Filters for IE7

# CSS Filters for IE7

Pingback from  CSS Filters for IE7

Friday, February 17, 2012 9:01 AM by water damage northridge

# re: Improving the CSS 2.1 strict parser for IE 7

Just make sure that you should carry on to develop a talk designed to make everybody impart more. You need to be mindful at what you said or maybe you might be set into a situation where nobody is ever going to act in response.

Thursday, February 23, 2012 3:01 AM by Webdesign

# re: Improving the CSS 2.1 strict parser for IE 7

Very crucial idea and tutorial to improve the CSS 2.1 strict parser for IE 7. I like this info very crucial so long. Thanks!

Monday, February 27, 2012 7:46 AM by online contest

# re: Improving the CSS 2.1 strict parser for IE 7

Have a nice tutorial! I honestly like this conception for improving the CSS 2.1 strict parser for IE 7. Hope the idea and tips will be educative. Thanks!

Saturday, March 03, 2012 9:42 AM by mini laptop

# re: Improving the CSS 2.1 strict parser for IE 7

Really educative tutorial! I'm amazed to read that brilliant input whatever you published. By the way I like this content amazingly. Thanks!

Wednesday, March 07, 2012 4:28 AM by Maile Ketzler

# re: Improving the CSS 2.1 strict parser for IE 7

If you wanna buy nfl jerseys,i wanna give you an advice:<a href=http://www.tiffany-co-outlet.net>Tiffany Co Outlet

</a> ,a real nice place that all kinds of nfl jerseys collected,high-quality,low-cost.And i think you'll love there!

Wednesday, March 07, 2012 7:13 AM by domain name hosting

# re: Improving the CSS 2.1 strict parser for IE 7

This is the perfect blog for anyone who wants to know about this topic. The article is nice and its pleasant to read. I have known very important things over here….

Wednesday, March 28, 2012 6:33 AM by Best website hosting

# re: Improving the CSS 2.1 strict parser for IE 7

The blog is absolutely fantastic. Lots of great information and inspiration, both of which we all need. Thanks

Friday, April 13, 2012 7:01 AM by Sam Jackie

# re: Improving the CSS 2.1 strict parser for IE 7

Just create sure that you should bring on to create a discuss developed to create everybody provide more. You need to be careful at what you said or maybe you might be set into a scenario where nobody is ever going to act in reaction.more

Wednesday, April 25, 2012 12:37 PM by Dylan

# re: Improving the CSS 2.1 strict parser for IE 7

Hi my loved one! I wish to say that this article is amazing, nice written and come with almost all important infos.

I would like to peer more posts like this .

Thursday, May 03, 2012 11:39 AM by Domingo

# re: Improving the CSS 2.1 strict parser for IE 7

Emplear una bicicleta eléctrica es una manera muy divertida de hacer

ejercicio. La bicicleta eléctrica combina el esfuerzo al poderse utilizar como una bici convencional, con la comodidad al

poder utilizar su motor para desplazarse. Está claro

que es una modo de transporte alternativo

que sabe convertir los viajes en un entretenimiento y son el futuro en

cuanto a formas de transporte.

Wednesday, May 16, 2012 5:56 AM by Eligibility for CNA Classes In Illinois

# re: Improving the CSS 2.1 strict parser for IE 7

I loved as much as you will receive carried out right here. The sketch is tasteful, your authored subject matter stylish. nonetheless, you command get got an edginess over that you wish be delivering the following. unwell unquestionably come more formerly again as exactly the same nearly a lot often inside case you shield this hike.

Sunday, May 20, 2012 6:17 PM by Buy Neopoints

# re: Improving the CSS 2.1 strict parser for IE 7

This is a wonderful article, you have a way with words. I find myself agreeing with a lot you have brought up. You have definitely earned yourself another reader! <a href="www.NeopointWarehouse.com">Buy Neopoints</a> , <a href="www.NeopointWarehouse.com">Neopoints For Sale</a> , <a href="www.NeopointWarehouse.com">Buy Neopets Neopoints</a>,  <a href="www.mytraffichits.com">Buy Website Traffic</a>, <a href="www.mytraffichits.com">Website Hits</a>, <a href="www.mytraffichits.com">Increase Website Traffic</a>

Wednesday, May 23, 2012 7:13 AM by CNA in Florida

# re: Improving the CSS 2.1 strict parser for IE 7

It is nice to know this. Thanks for the time and effort. It is well appreciated. More to come.

Leave a Comment

(required) 
(required) 
(optional)
(required)