Velocity 2011 (#velocityconf): CSS3 - Beyond the Hype!
I abbreviated the title here a bit because the talk was really just about CSS3. Nicole Sullivan provided some useful tips about dealing with CSS in general, especially some of the features of CSS3.
As usual, the overall name of the game is graceful degradation with good performance. While IE6 (which we will seemingly never be rid of) does not support any of these features, that may not be a big issue. Rounded corners, drop shadows, and transparency can just become square corners, no shadow, and opacity. Is that really a huge issue? Will the IE6 users be saddened by not having rounded corners? How will they know unless they have a newer browser somewhere?
There are other features that won't degrade as well. The provided example was the carat in a breadcrumb. There's a unicode character that you can use in the CSS to provide this, but it won't work in IE6. You need to provide some sort of explicit fallback here.
In the end, it's about balance. You need to find a good compromise in the middle.
Then, we got into the tips. There were a few really notable tips. First, we'll talk about CSS selectors. I didn't know before this that they are evaluated right to left. The browser will use the right-most constraint to find all the elements that match and then traverse up the tree until the matches are weeded out. At first, this seems absolutely terrible. If you think about the actual way the DOM and selectors are implemented, it starts to make sense why this happens. Traversing from the root up the tree is painful because a child selector may not be immediately beneath the parent. It could be several levels deep. Starting from the deepes part makes the most sense, algorithmically. This also means that selectors ending in a * begin with ALL elements in the DOM and filter from there. That's a very bad idea.
Additionally, regex and attribute selector patterns are considerably slower (for fairly obvious reasons), so they are also discouraged. The real shock (which also makes sense when you really sit down to think about how the browser has to work) is that specifying something like "div.foo" is slower than saying ".foo". This is because the class is found first, then they make sure that it's a div tag that was found. I don't believe that there is a drastic difference, but you shouldn't really have classes that are shared among different tag types if you want them to behave differently on the tag types in question.
Finally, Nick Zakas and Nicole announced at the end that they had written a new CSS Lint tool that covers all of this and more. It's written in JavaScript, and they open sourced it right in front of us on github. If you have ideas, you should go and look at it. They are happy to take more rules.