CSS3 came with a new set of selectors providing more ways to specify the DOM elements to apply the styling. Utilizing them can save some DOM manipulation done by JavaScript which makes your app run more efficiently. While many of the CSS3 properties are not supported by IE version 9 or below, most of the CSS3 selectors with only a few exceptions are supported by IE9. Make sure you are aware of them and start using them whenever you can.
- Attribute Selectors
[data-action-type ^= "add"] - the element with data-action-type attribute and the value starts with "add". [data-action-type $= "add"] - the element with data-action-type attribute and the value ends with "add". [data-action-type *= "add"] - the element with data-action-type attribute and the value contains "add".
- Combinator
F ~ E - the element that's following element F E + F - the element that's immediately following element F (CSS2)
- Pseudo-class Selectors
E:target - the element that was targeted. E:empty - the element that has no children E:not(s) - the element that does not match CSS selector s E:nth-child(n) - the n-th child of the element E:nth-child(odd) - the odd number child of the element. Can be even as well. E:nth-last-child(n) - the n-th child from the last one of the element E:first-child - first child of the element (CSS2) E:last-child - last child of the element E:only-child - only child of the element E:nth-of-type(n) - the n-th element of E's type E:nth-last-of-type(n) - the n-th element from the last one of the type E:first-of-type - first element of the type E:last-of-type - last element of the type E:only-of-type - the only element of the type
Below is an example of a tab container without using JavaScript. Click on the tab title to view the content. The default tab can be selected by adding the hash tag in the URL.
- Other CSS1/2 Selectors you may have missed
E[data-action-type] - the element that has data-action-type attribute E::first-line - first line of the element E::first-letter - first character of the element E::before - add content before the element E::after - add content after the element
Related readings:
CSS3 specification: w3.org/TR/css3-selectors/#simple-selectors
CSS3 and HTML5 browser support: findmebyip.com/litmus

