Did the ::content syntax change?

185 views
Skip to first unread message

Jan Miksovsky

unread,
Mar 14, 2014, 8:08:38 PM3/14/14
to polym...@googlegroups.com
I just upgraded Canary to 35.0.1892.2, and CSS rules with ::content CSS selectors no longer seem to be applied as expected. I'm wondering if the ::content syntax changed recently.

As far as I know, the syntax for ::content looks like:

::content * {
  color
: red;
}

This is what's shown in the Guide to Styling article on the Polymer site, for example.

Repro: http://jsbin.com/gacogeda/1/editThis jsbin works in an older Canary (35.0.1887.0), but not in the latest Canary.

I also happened to notice a recent Polymer checkin that used a different content syntax like:

::content(*) {
}

But I haven't seen a breaking change announcement anywhere — did I miss it?

Steve Orvell

unread,
Mar 14, 2014, 8:41:47 PM3/14/14
to Jan Miksovsky, polym...@googlegroups.com
Yes, it was changed to match the spec here: http://dev.w3.org/csswg/shadow-styling/.

The ::content pseudo-element was removed. The /content/ combinator was added. So your rule could be:

content /content/ * { color: red; }

Note, a combinator must have some selector to the left of it.

In addition the ^ and ^^ combinators were renamed to /shadow/ and /shadow-deep/.

Hope that helps.


Follow Polymer on Google+: plus.google.com/107187849809354688692
---
You received this message because you are subscribed to the Google Groups "Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to polymer-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/ad7d90f6-16de-43b2-9ce1-20d019f6ff36%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jan Miksovsky

unread,
Mar 14, 2014, 9:43:06 PM3/14/14
to polym...@googlegroups.com, Jan Miksovsky
Ah, thanks. I'd seen discussion of /shadow/ and /shadow-deep/, but not /content/.

Should /content/ work right now? The updated jsbin at http://jsbin.com/gacogeda/2/edit still doesn't seem to work. Or are we in some place where ::content no longer works, but /content/ doesn't work yet?

Eric Bidelman

unread,
Mar 16, 2014, 5:40:25 PM3/16/14
to Jan Miksovsky, polymer-dev
That works for me in the latest Canary (35.0.1895.0). For polyfill support, you still need to add the equivalent polyfill-next-selector {} rule. This should work in Canary (with flags) and stable:



Jan Miksovsky

unread,
Mar 18, 2014, 1:21:20 AM3/18/14
to polym...@googlegroups.com, Jan Miksovsky
Eric: Thanks. I could have sworn the native form *didn't* work for me in Canary when I posted this, but it works now. So I was either hallucinating, or the problem was fixed quickly. Either way, glad to know I can /content/ as expected.

Hoa V. Dinh

unread,
Mar 19, 2014, 1:30:14 AM3/19/14
to Jan Miksovsky, polym...@googlegroups.com
Hi,

On the same topic, I was wondering how to write the equivalent of such a selector with the new syntax:
:host([direction="left"]:host) > content[select=":nth-child(2)"]::content > *

See:

-- 
Hoa V. Dinh

Rob Dodson

unread,
Mar 19, 2014, 1:56:48 AM3/19/14
to Hoa V. Dinh, Jan Miksovsky, polymer-dev
Hi Hoa,

I think that would be...

:host([direction="left"]) > content[select=":nth-child(2)"] /content/ *


I think I got that right :) Let me try to explain...

You no longer need to do :host(.foo:host) to match a shadow host with class .foo. Previously you needed the second :host in there to make sure you were selecting only the shadow host and not an ancestor. Now we have the :ancestor() selector, so :host() only targets the shadow host itself.

as we mentioned ::content has been replaced by /content/, so that part changes

lastly, the thing to the right of /content/ must always be a top level element. so content /content/ * will select any distributed top level element, which looks like what you were previously trying to achieve with ::content > *

one thing to note, there's a chrome bug that causes /content/ * .something-else to not work at the moment (https://code.google.com/p/chromium/issues/detail?id=353606). But I think content /content/ * will still work... Let me know if you have issues :D


Sergey Shevchenko

unread,
Mar 19, 2014, 4:18:07 PM3/19/14
to polym...@googlegroups.com, Hoa V. Dinh, Jan Miksovsky
Thanks, Steve, Eric and Rob. One more question: I can't get the old and the new syntax to work when the two selectors are separated with a comma and listed in front of a single rule:

/* Doesn't work: */
::content > *, * /content/ * {
  color: red;
}

/* Works: */
::content > * {
  color: red;
}
* /content/ * {
  color: red;
}

This is very inconvenient, especially for large rules. We need to keep both for a while for the code to work across the latest Dartium and Chrome on Windows/Max/Linux. I was able to get similar old-vs-new syntax to work before, e.g. when :host.something changed to :host(.something).

Also, could changes like this be rolled out gradually, with a transitional period when both syntaxes are supported and the old one reported as deprecated, e.g. in the console? This abrupt change has disrupted our work here at Spark quite a bit yesterday.

Rob Dodson

unread,
Mar 19, 2014, 4:26:51 PM3/19/14
to Sergey Shevchenko, polymer-dev, Hoa V. Dinh, Jan Miksovsky
Hm that sounds like a bug. Pinging @sorvell


Eric Bidelman

unread,
Mar 19, 2014, 5:22:09 PM3/19/14
to Sergey Shevchenko, polymer-dev, Hoa V. Dinh, Jan Miksovsky

IIRC, an invalid selector in Blink will make the entire rule not work. So even though the second rule is valid, the first (using ::content) is no longer valid and the rule is thrown out.

FWIW, disruptive changes like this won't happen when the native stuff snips.  We're so close to that inflection point that final spec updates are still being made. It's an unfortunate side effect of using features when they're still behind a flag. We've tried to announce Blink updates on this list, but it's understandable not everyone sees those updates :)

Sergey Shevchenko

unread,
Mar 19, 2014, 7:01:58 PM3/19/14
to polym...@googlegroups.com, Sergey Shevchenko, Hoa V. Dinh, Jan Miksovsky

On Wednesday, March 19, 2014 2:22:09 PM UTC-7, Eric Bidelman wrote:

IIRC, an invalid selector in Blink will make the entire rule not work. So even though the second rule is valid, the first (using ::content) is no longer valid and the rule is thrown out.

This makes sense... However, I can't explain why the following worked then:

:host[direction=up], :host([direction=up]) {
...
}

This was after Chrome had switched to the latter syntax, but Dartium was still using the former. Maybe it's that :host([direction=up]) wasn't "as broken" as /content/ from the Blink's perspective? Anyway, that doesn't matter anymore, I guess.

 

FWIW, disruptive changes like this won't happen when the native stuff snips.  We're so close to that inflection point that final spec updates are still being made. It's an unfortunate side effect of using features when they're still behind a flag. We've tried to announce Blink updates on this list, but it's understandable not everyone sees those updates :)

Can't wait until we flip the native support for everything and are in a more-or-less stable land! :) 

Eric Bidelman

unread,
Mar 19, 2014, 7:08:22 PM3/19/14
to Sergey Shevchenko, polymer-dev, Hoa V. Dinh, Jan Miksovsky

That may be because polymer's shimming supported both in a small deprecation window?

Sergey Shevchenko

unread,
Mar 20, 2014, 4:38:06 PM3/20/14
to Eric Bidelman, polymer-dev, Hoa V. Dinh, Jan Miksovsky
Possible...

Rob Dodson

unread,
Mar 21, 2014, 1:52:29 PM3/21/14
to polym...@googlegroups.com, Eric Bidelman, Hoa V. Dinh, Jan Miksovsky
I wanted to share this with you guys because we've been talking a lot about this particular topic over the past few days. It looks like the proposal is to move /content/ back to the previous ::content syntax, /shadow/ back to the previous ::shadow syntax, and /shadow-deep/ to just /deep/. These changes are now captured in a draft spec which you can monitor to keep tabs on any changes.

CSS Scoping Module Level 1

Sorry for all of the churn, but after working with /content/ for a little while it was decided that the new combinator syntax (/content/) was all cost with little gain. For instance, using /content/ meant having to select the content element on the left hand side (usually done with a * for brevity) and specify a top level element immediately to the right of the combinator, even if you weren't targeting that element. Ex:

* /content/ ul li

The previous pseudo selector did not have this same limitation so you could just do ::content li.

The /content/ syntax also prevented the use of >, because you can't have a combinator followed by a combinator. So it would be impossible to do * /content/ > .my-thing. Again, the pseudo syntax does not suffer from this limiation, ::content > .my-thing is totally valid.

Obviously it's super annoying for early adopters, like you guys, because we go one way, then another, then back to where we started :) But after using the new syntax it just didn't feel right and we wanted to make sure we weren't shipping something that folks were going to hate years into the future.

Rob Dodson

unread,
Mar 21, 2014, 1:53:57 PM3/21/14
to polym...@googlegroups.com, Eric Bidelman, Hoa V. Dinh, Jan Miksovsky
Another thing to add, native support for /content/ has been reverted in blink and the old ::content syntax should be shipping in Canary any day now.

Jan Miksovsky

unread,
Mar 21, 2014, 2:04:49 PM3/21/14
to polym...@googlegroups.com, Eric Bidelman, Hoa V. Dinh, Jan Miksovsky
Aaaaaaagh. I just spent a couple of hours yesterday upgrading a pile of elements to the new syntax. And, because I ended up making a variety of other edits while I was in there, I can't just roll back. Now I can block out an hour or so next week to put the old syntax back.

I'm actually fine with the decision (I'd been disappointed by the inability to combine /content/ with ">"), and you did recognize the fact that this is annoying and causes trouble for early adopters. But: Yes! Churn like this really does cause a lot of work.

Jan Miksovsky

unread,
Mar 21, 2014, 2:05:29 PM3/21/14
to polym...@googlegroups.com, Eric Bidelman, Hoa V. Dinh, Jan Miksovsky
Aaaaaaagh. I just spent a couple of hours yesterday upgrading a pile of elements to the new syntax. And, because I ended up making a variety of other edits while I was in there, I can't just roll back. Now I can block out an hour or so next week to put the old syntax back.

I'm actually fine with the decision (I'd been disappointed by the inability to combine /content/ with ">"), and you did recognize the fact that this is annoying and causes trouble for early adopters. But: Yes! Churn like this really does cause a lot of work.

Rob Dodson

unread,
Mar 21, 2014, 2:31:49 PM3/21/14
to polym...@googlegroups.com, Eric Bidelman, Hoa V. Dinh, Jan Miksovsky
Hey Jan,

I agree and I feel your pain because I have the same refactoring task ahead of me. The spec was drafted yesterday late afternoon after a couple days (and nights) of serious discussion. We realized we were making a mistake and we didn't want to ship something that would suddenly be frozen and trip others up for years to come.

In the future, if I see rumblings of some kind of dramatic change, I might play the part of canary and squawk a bit on the list. I don't want to raise a bunch of false alarms, but we're all part of a big team here and everyone deserves to be as "in the know" as possible.
Reply all
Reply to author
Forward
0 new messages