I am not well versed in CSS. Â I can get around. Â I can make a site look pretty good in Safari and horrible in Internet Explorer (look at this site in IE for a great example). Â But I’m a hacker at best. Â I fiddle with CSS until something looks right, I don’t follow conventions or standards, I don’t know what a box-model hack actually does, and I can’t even begin to tell you how to write browser specific CSS styles.
If you are a like me then Shaun Inman’s proposal for CSS Selectors will probably leave you with a furled brow.
Rather then being left standing in the dark I tried to wrap my head around what Shaun was trying to accomplish with his proposal. Â I didn’t get. Â But I wanted to. Â So I setup a quick example page that illustrated my question. Â I then hopped, skipped, and jumped over the Shaun’s Web site, and asked what I was missing. Â Shaun, kindly andÂ succinctly, replied.
The non-CSS guru explanation of the CSS Selector proposal
I can’t be sure that any of you reading this are in the same boat as I was. Â In fact, I’m sitting here thinking at all of you are smarter than I am when it comes to these things, and that you’re not even reading this right now. Â But if you are, and you’d like to understand this debate a little further, here is as simple an explanation as I can give.
A style can not be attributed to a parent element when a specific child element is present.
I don’t even know if I worded that correctly. Â I’m pretty sure I didn’t. Â So here is the long-winded version. Â In Shaun’s first example he shows that an image, that is wrapped with a link, would have the same style as a normal link. Â The problem is that, currently, CSS can not determine the differences between a normal link and a link that has an image within it. Â It just isn’t “smart” enough. Â That is, without the help of something that runs after the DOM has loaded fully like the awe-inspiring John Resig’s jQuery plugin.
Shaun’s proposal is to help make CSS, and browsers, “smart” enough to determine when styles should be attributed to links and when not to be attributed to links that contain images. Â This was only his first example, Shaun gives others.
I really hope I did an okay job explaining this for those of you that, like me, didn’t understand it before pounding my head against my desk.
Shaun has hit me back with a succinctÂ definitionÂ that correctly uses the lingo.
“CSS allows you to style elements based on their parent/ancestor elements but it does not allow you to style a parent element based on the presence of a descendant element.”
You can look backwards, but you can’t look forwards. Â Thanks Shaun!