CSS4 Preview – Selectors
davidwalsh.name
davidwalsh.name
* el < el
I've run into many situations over the years where being able to select parent elements based on a child would have come in handy. I think it would be a lot simpler to just use < for direct parents, as > is used for direct children.
The ampersand character (&) and the left angle bracket (<) MUST NOT appear in their literal form, except when used as markup delimiters, or within a comment, a processing instruction, or a CDATA section. If they are needed elsewhere, they MUST be escaped using either numeric character references or the strings " & " and " < " respectively.
The right angle bracket (>) may be represented using the string " > ", and MUST, for compatibility, be escaped using either " > " or a character reference when it appears in the string " ]]> " in content, when that string is not marking the end of a CDATA section.
Completely agree! It should be possible to do this.
And please: vertical-align:center for any block element. Or is that in CSS3 and I am not aware of it?
Can somebody explain the slash syntax in the example given?
label:matches(:hover, :focus) /for/ input { <label for="first_checkbox">A label</label>
<input type="checkbox" id="first_checkbox" />
<label for="another_checkbox">Another label</label>
<input type="checkbox" id="another_checkbox" />
And css: label:matches(:hover, :focus) /for/ input {
margin: 30px;
}
If the user then hovers the first label (for="first_checkbox") the input (id="first_checkbox") will get an annoying margin.The syntax uses the id named in the for-attribute to connect with the element with the same id.
Not really, although it's a bit weird the `//` operator is a relation (like the space, or `>`). It "just" works sideways (and potentially upwards) instead of selecting strictly downwards.
ul > li > p
ul > $li > p
have the same matching complexity: the browser finds all p on the page, then checks if their parent is a li, then checks if that parent is a ul. The difference (which may or may not require significant work) is that before the check acted as a filter on the originally matched object, whereas now there's a transform/translation.el /if/ el > .someclass:hover { some:style; }
Style an element "el" if some other element exists or event occurs.
Again, insteat of being able to just select a parent on the existence of a child, why not be able to select any element on the existence of another element? Change the background of a body > div if there is only one child in a list body > ul > li:only-child for example.
body > div /if/ body > ul > li:only-child { background:green; }
Or replace /if/ with :: or $ or whatever.
It's a reference indirection going through an IDREF type:
* It finds whatever elements are before the operator
* It gets the value of the operator's attribute (or type IDREF), ~ storing it in $ID
* it combines the selector after it with the root being extended with `[id=$ID]`
`/if/` would get the value of the attribute `if` and try to find an element with that value as its id.
body > div:if(body > ul > li:only-child) { background:green } body > div:not(body > ul > li:only-child) { background:green }
which may or may not already work in CSS3.
Issue here is that you're talking about this using syntax for something which has absolutely no relation. Which is a tad confusing.
No, what you want does not work in CSS, you can't make a selector conditional on a second completely unrelated selector (you probably can in XPath, although I'm sure your colleagues will soon look to end your life if you do)
div.status > span:on(div.clickme > a:hover) { display:block; }
Why would that be bad?
It's "action at a distance", it's very, very hard to understand and debug what happens.
Your argument is not very convincing.
You don't have to have all of CSS3 implemented everywhere to be useful. Same for CSS4.