Re: Selector Sugar

 -------------- Original message ----------------------
From: François REMY <fremycompany_pub@yahoo.fr>
> 
> From: "Brad Kemper" <brkemper.comcast@gmail.com>
> >
> >
> > On Oct 9, 2008, at 8:53 AM, Tab Atkins Jr. wrote:
> >
> >> I want to talk about two issues of syntactic sugar that I believe  would 
> >> be very useful to us authors.  [..........]
> >>
> >> (1) Scoped selectors within a stylesheet.
> >>
> >>  [.........]
> >>
> >> (2) Multi-matching selector
> >>
> >>  [.........]
> >>
> >> ~TJ
> >
> > I agree that those would be valuable. [........]
> >
> > I wonder if it might even be possible to leave out the @scoped, and  just 
> > have it like this to do the same thing:
> >
> > #nav-menu {
> > h1 {
> > //This is equivalent to the selector "#nav-menu h1",
> > //and so won't target <h1>s across the rest of the page.
> > ...
> > }
> > ul {
> > ...
> > }
> > more rules...
> > } //end of scope
> 
> I agree with you but there's a problem :
> 
>     li.hoverLink {
>         a:hover,
>         a:focus {
>             color: red;
>          }
>     }
> 
> The parser will think that 'a' is a property and 'hover,' a value, and that 
> the property incorectly ended.

Good point. But I was assuming the parser would need to be updated to deal with this either way. If, when matching tokens, it looks for things that look like selectors first and only looked for property:value combinations when that failed, couldn't that work?

> With another syntax, like an at-rule, it should delete this problem.
> 
>     li.hoverLink {
>         @rule a:hover, a:focus {
>              color: red;
>         }
>     }
> 
> The problem with this, is that we introduce the use of at-rules in the 
> selectors, and it was not existing before.
> Some old browers can think we have :
> 
>     li.hoverLink {
>         // bad line
>         color: red;
>         // bad line
>     }
> 
> So, as I prefer a 'not-friendly' solution (@scope and :any) than no solution 
> at all, I agree to discuss this...
> Fremy 

I prefer the @scope to the @rule. With @rule, you would have to add it in a lot of times, once for every rule within the context, and isn't the point that we don't want to keep adding a prefix multiple times?

Regarding old browsers: They are virtually guaranteed to draw the page incorrectly if it has any of this sort of mark-up in it, because they will be ignoring large swathes of CSS inside the braces. So why bother trying to play nice with them? An author would need to be very careful with actually using this, only doing so when he or she is confident that it is likely going to a UA that can handle it (through UA-detection, perhaps, or by knowing the audience, or by controlling the UA that reads the markup).

Received on Friday, 10 October 2008 01:50:25 UTC