News for hackers. Stuff that matters.
Re:CSS4 Preview – Selectors by garindra on Tuesday March 06, 2012 @06:50PM (#3673494)
What about LESS-style nested selectors? I've been using it in my projects and it improves my workflow tremendously. I'd be thrilled if it's finally integrated into the CSS specification.
Re:CSS4 Preview – Selectors by jacobr on Wednesday March 07, 2012 @06:32AM (#3675093)
Might be harder to pull off wrt backwards compatibility.
Re:CSS4 Preview – Selectors by bps4484 on Wednesday March 07, 2012 @01:28PM (#3676519)
how so? Sass and Less seem to be able to pull it off.
Re:CSS4 Preview – Selectors by geuis on Tuesday March 06, 2012 @08:49PM (#3673892)
Instead of $el > el syntax, wouldn't a simple version be better?

* 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.

Re:CSS4 Preview – Selectors by saurik on Tuesday March 06, 2012 @09:10PM (#3673943)
A) Using < would cause parsing problems when the stylesheet is embedded in an enclosing HTML document. B) If you think about it, the selector is still functioning the same: you are simply moving which node is being "targeted"; I would therefore hope that you could also do "$el + el" to select nodes that came before other nodes. (edit: Reading the linked update to the specification, it seems like the people who wrote it did not see that this would be a useful, beautiful, and arguably important generalization; sigh.)
Re:CSS4 Preview – Selectors by bps4484 on Wednesday March 07, 2012 @01:27PM (#3676503)
could you elaborate on A? What's the problem of using "<" in an enclosing html document that wouldn't also be a problem for ">", which already exists?
Re:CSS4 Preview – Selectors by saurik on Wednesday March 07, 2012 @03:00PM (#3676871)
I'm confused by your comment: ">" only has special meaning in the context of a tag, or after "]]"; "<" has special meaning meaning anywhere in a document you are not inside of a tag.
Re:CSS4 Preview – Selectors by bps4484 on Friday March 09, 2012 @02:35PM (#3685578)
that actually answered my question. I don't know the html spec that well so I didn't know if both "<" and ">" were reserved characters. From what I understand of what you're saying, it's only when ">" comes after a "<" that is has special meaning.
Re:CSS4 Preview – Selectors by saurik on Friday March 09, 2012 @02:53PM (#3685637)
Correct. From the XML specification (which is easier to obtain than SGML, more prescriptive than HTML4, and capable of being understood by humans in a way the HTML5 "document IE" specification is unable to support), 2.4 "Character Data and Markup" (note the "may" and "MUST"):

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 " &amp; " and " &lt; " respectively.

The right angle bracket (>) may be represented using the string " &gt; ", and MUST, for compatibility, be escaped using either " &gt; " or a character reference when it appears in the string " ]]> " in content, when that string is not marking the end of a CDATA section.

Re:CSS4 Preview – Selectors by bps4484 on Wednesday March 07, 2012 @01:25PM (#3676492)
I thought the same thing when I read about "$" and thought they should use "<" as you suggest. I don't like that the last element in a chain of css isn't the target.
Re:CSS4 Preview – Selectors by yaix on Wednesday March 07, 2012 @02:51AM (#3674716)
There is one good point in the comments: "MATH! We need math! 50% -5px It’s stupid having to do things like this in JS."

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?

Re:CSS4 Preview – Selectors by Twisol on Wednesday March 07, 2012 @03:42AM (#3674823)
You can use calc (https://developer.mozilla.org/en/CSS/calc), but it isn't well supported.
Re:CSS4 Preview – Selectors by chrisbroadfoot on Tuesday March 06, 2012 @06:30PM (#3673431)
I like the $ syntax. It's powerful.

Can somebody explain the slash syntax in the example given?

    label:matches(:hover, :focus) /for/ input {
Re:CSS4 Preview – Selectors by eCa on Tuesday March 06, 2012 @06:45PM (#3673482)
Consider the following html:

  <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.

Re:CSS4 Preview – Selectors by chrisbroadfoot on Tuesday March 06, 2012 @07:18PM (#3673606)
Right. I get it. Basically an infix notation. Seems inconsistent with the rest of CSS.
Re:CSS4 Preview – Selectors by driax on Wednesday March 07, 2012 @01:52AM (#3674584)
Well every other operator is infix, so it's not really that inconsistent. " " (space) selectes descendents, ">" selects children, "+" selectes next-siblings and so on. The weird feeling of "/{attr}/" is probably just that the operator is variabel on the name of the attribute, which can't be avoided by any syntax (given that is part of the needed semantics).
Re:CSS4 Preview – Selectors by masklinn on Wednesday March 07, 2012 @07:20AM (#3675194)
> Seems inconsistent with the rest of CSS.

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.

Re:CSS4 Preview – Selectors by tlb on Tuesday March 06, 2012 @08:26PM (#3673817)
It's easy to cook up a syntax for selecting parents. The hard part is implementing it efficiently. It requires browsers to scan more of the DOM tree when elements are changed. I expect it to be one of the (many) parts of CSS that are avoided by websites that want to render quickly.
Re:CSS4 Preview – Selectors by masklinn on Wednesday March 07, 2012 @03:37AM (#3674812)
I'm not sure, CSS selectors are already matched left-to-right so you're not scanning more stuff, it's just that you're selecting an other level of your match tree.

    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.
Re:CSS4 Preview – Selectors by masklinn on Wednesday March 07, 2012 @07:15AM (#3675183)
s/left-to-right/right-to-left/ of course
Re:CSS4 Preview – Selectors by snookca on Tuesday March 06, 2012 @09:04PM (#3673925)
Exactly. And just because there's a draft specification, doesn't mean browsers will implement it.
Re:CSS4 Preview – Selectors by cleverjake on Tuesday March 06, 2012 @06:32PM (#3673438)
"The example above highlights an INPUT element when its LABEL is focused or hovered-over; the association is made by the for attribute of the label. As you can probably tell, the id is implied by the LABEL element's for attribute."
Re:CSS4 Preview – Selectors by md224 on Wednesday March 07, 2012 @02:32AM (#3674665)
This article might be a bit out of date... it appears the $ selector has been changed to an exclamation point:

http://dev.w3.org/csswg/selectors4/#subject

Re:CSS4 Preview – Selectors by masklinn on Wednesday March 07, 2012 @03:29AM (#3674795)
I'm not sure how I feel about CSS selectors closing in on XPath 1.0 in terms of power, except with far, far higher levels of syntactic complexity.
Re:CSS4 Preview – Selectors by yaix on Wednesday March 07, 2012 @02:43AM (#3674695)
Why only select an element based on its children? How about

el /if/ el > .someclass:hover { some:style; }

Style an element "el" if some other element exists or event occurs.

Re:CSS4 Preview – Selectors by yaix on Wednesday March 07, 2012 @03:21AM (#3674771)
wtf? Why do I get downvoted? Could the downvoter explain please.

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.

Re:CSS4 Preview – Selectors by masklinn on Wednesday March 07, 2012 @03:33AM (#3674805)
I'm not sure you understand what /op/ does.

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.

Re:CSS4 Preview – Selectors by yaix on Wednesday March 07, 2012 @03:39AM (#3674818)
Again, what I care about is not the syntax but the functionality. If you want write it as

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.

Re:CSS4 Preview – Selectors by masklinn on Wednesday March 07, 2012 @07:18AM (#3675190)
> Again, what I care about is not the syntax but the functionality.

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)

Re:CSS4 Preview – Selectors by yaix on Wednesday March 07, 2012 @09:52AM (#3675647)
Could you explain why? Let's say you have a clickable element and want to display a status text on hover. The status texts are loaded in some divs somewhere else on the page. You would need JS to catch onhover and then swap the display:hidden to block or whatever. Why would anybody look to "end my life" if that was possible?

div.status > span:on(div.clickme > a:hover) { display:block; }

Why would that be bad?

Re:CSS4 Preview – Selectors by masklinn on Thursday March 08, 2012 @04:51AM (#3679190)
> Why would that be bad?

It's "action at a distance", it's very, very hard to understand and debug what happens.

Re:CSS4 Preview – Selectors by yaix on Friday March 09, 2012 @10:35AM (#3684428)
(1) You mean like when you do the same thing with Javascript? Why its okay then? (2) If you alter a parent element with CSS that's "action on a distance" as well.

Your argument is not very convincing.

Re:CSS4 Preview – Selectors by wavephorm on Tuesday March 06, 2012 @09:16PM (#3673955)
Given the number of years it'll take for CSS3 to be used reliably, this information isn't very useful.
Re:CSS4 Preview – Selectors by batista on Wednesday March 07, 2012 @06:18AM (#3675076)
Given that you can target modern browsers like Chrome and Safari and Firefox, and either fuck IE and older versions (e.g for an inhouse app) or just have then not support some fancy features, it's VERY useful.

You don't have to have all of CSS3 implemented everywhere to be useful. Same for CSS4.