As an example, imagine I have a table. The standard alignment behaviour (not sure if this is html specification or just the browsers I use?) seems to be to left align the body elements and center align the head elements.
So if I wanted everything left aligned, is it less efficient to write
#MyTable td {
text-align: left;
}
than to write
#MyTable tbody td {
text-align: left;
}
Or does it not really make any difference?
What is best practice in this situation?
I guess my question is really about how “default” styles get set. Are they actually explicitly set by the browser if no matching style if found in the css? Or are they genuine default behaviours when no style is present.
You can see the browser’s default and computed style with firebug/webkit built-in inspector. The selector matching goes from the right to the left. So the first should be faster, in theory. In practice there is hardly any difference. Even for ~100 elements.
But if you want to write efficent selectors the rule is simple:
Be the rightmost selector as specific as it can be.