- Determining the subject of a selector. Currently, if a selector consists of several compound selectors, the last one is considered its subject. The subject determines what elements the rule applies to. CSS 4 allows one to make any compound selector the subject, by prepending a dollar sign. For example:
$ul li:hover { color: green; }Here, if one hovers over a list element, the whole list will turn green. This is a great and dearly needed feature. - Pseudo-class :nth-match(). Lets you apply a rule to every n-th match for a given selector list.
:nth-match(an+b of selector-list)Previously, you could only access every n-th child. This selector gives you more flexibility. - UI states pseudo-classes allow you to style elements depending on their user interface state. Examples: :disabled, :checked (radio elements, checkbox elements, menu items, etc.), :in-range (for input elements with range limitations).
- The matches-any pseudo-class :matches(). Example:
:matches(section, article, aside) h1 { font-size: 3em; }The above selector is an abbreviation forsection h1, article h1, aside h1 - The contextual reference element pseudo-class ‘:scope’. When you use selectors to query for elements, you can start your search in a list of elements that is iterated over, one element at a time. :scope is a placeholder for the current element. Example:
document.querySelector(":scope > ul > li", elems)The above returns all list items that are direct children of unordered lists that are direct children of the elements in elems.
2011-12-13
What’s new in CSS 4 selectors
The following are the highlights of what is new in CSS 4 selectors:
Subscribe to:
Post Comments (Atom)
8 comments:
surely the first one would work with ul:hover {color:Green;} - not sure why it's special or needed?
The 4th one is awesome though!
No, it's not the same. In the first example above, the style actually gets applied to the list element (the ul) rather than the li element that was clicked. This is the point of the new subject selector. It allows rules to be applied to something other than the innermost-selected element (which, in this case, would be the clicked li element) and instead apply it to whatever you have selected as the subject.
I'm already geeking out over being able to use :matches. :nth-match should also induce interesting moments of clever.
This is the long wanted, requested, demanded and expected parent selector! But better!!
A row, highlighted by a descendant checkbox:$tr > td:first-child > :checked { background-color: lime;}
Awesome!!
This is going to break CSS code highlighting algorithms in so many editors :)
oops I parse my css with PHP... guess need to think of an exit strategy
how will these new selectors affect performance? If they have a large performance hit then they wont be that useful of some devices
document.querySelector(":scope > ul > li", elems)
The ':scope' seems a bit redundant, if elems is provided, it should by default search in the given context, like jquery does.
Post a Comment