Skip to content

[css-contain] Do scoped counters create new counters? #1887

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Loirooriol opened this issue Oct 17, 2017 · 7 comments
Closed

[css-contain] Do scoped counters create new counters? #1887

Loirooriol opened this issue Oct 17, 2017 · 7 comments

Comments

@Loirooriol
Copy link
Contributor

From Style Containment,

For example, if counter-increment is scoped to an element, the first use of it within the subtree acts as if the named counter were set to 0 at the scoping element, regardless of whether the counter had been used outside the scoping element. Any increments made within the subtree have no effect on counters of the same name outside the scoping element.

But it's not much clear if a scoped counter-increment creates a new counter or not.

That is, what is the expected output of

<div></div>
div {
  contain: style;
  counter-increment: n;
}
div::before {
  counter-increment: n 2;
  content: counters(n, '.');
}

Is it 1.2 or just 2?

@Loirooriol
Copy link
Contributor Author

OK, since content is scoped, I think the output is just 2.

But note that CSS Lists will allow counters() anywhere that accepts a <string>, so what about background: url( counters(n, '.') )? Is the background image retrieved from 1.2 or just 2?

Maybe you should scope counters() itself.

@css-meeting-bot
Copy link
Member

The Working Group just discussed Scoped Counters, and agreed to the following resolutions:

  • RESOLVED: create new counter scopes at style scoping root for style containment
The full IRC log of that discussion <fantasai> Topic: Scoped Counters
<astearns> github: https://github.com//issues/1887
<fantasai> TabAtkins: If you have a style scoped element, which says counters are scoped to the subtree
<fantasai> TabAtkins: does that create a new counter?
<fantasai> s/that/counter-increment/
<fremy> +1 on this one
<fantasai> TabAtkins: or does it increment the existing counter from the outside
<fantasai> TabAtkins: I think it should implicitly create a new counter scope at the style scoping root
<fantasai> fantasai: And so counters() would reveal a new level of counter?
<fantasai> TabAtkins: yes
<fantasai> TabAtkins: Don't want to fuss with the subtree when calculating counters further down in the document
<fantasai> fantasai: so you're disagreeing with Oriol's comment?
<fantasai> TabAtkins: ...
<fantasai> astearns: Write a test?
<TabAtkins> s/.../yes/
<fantasai> astearns: So proposed to implicitly create new counter scopes at style scoping root for style containment
<fantasai> RESOLVED: create new counter scopes at style scoping root for style containment

@frivoal
Copy link
Collaborator

frivoal commented Mar 29, 2018

@Loirooriol The resolution agrees with you that it needs to be defined, but defines it differently from what you suggested. Please confirm that this outcome is acceptable to you.

@Loirooriol
Copy link
Contributor Author

The behavior is acceptable, but I think the spec is a bit confusing because it says that content is scoped, i.e

must act as if the scoping element was the root of the document for the purpose of evaluating the property’s effects

but then content can read counter values from ancestors. So it doesn't really act as the root.

@frivoal
Copy link
Collaborator

frivoal commented Mar 29, 2018

I guess the problem is that it says that content is scoped (for the purpose of open-quote/etc values) and that the etc doesn't make it totally clear what is concerned and what is not.

@frivoal
Copy link
Collaborator

frivoal commented Mar 29, 2018

@Loirooriol I opened #2483 to follow up on this.

@Loirooriol
Copy link
Contributor Author

Yes, that's the problem.

BTW, Chrome outputs 2 instead of 1.2. Somebody should tell them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants