Skip to content
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

[css-lists] Does counter() create a new counter if none exists? #2348

Closed
Loirooriol opened this issue Feb 22, 2018 · 5 comments
Closed

[css-lists] Does counter() create a new counter if none exists? #2348

Loirooriol opened this issue Feb 22, 2018 · 5 comments

Comments

@Loirooriol
Copy link
Contributor

Consider this code: https://jsfiddle.net/35kuzg5m/

<div>
  <p>aaa</p>
  <p>bbb</p>
</div>
<hr />
<div>
  <p>aaa</p>
  <p>bbb</p>
</div>
p::before {
  content: counter(c) '/ ';
  counter-increment: c 1;
}
div ~ div::before {
  content: counter(c, none);
}

It's rendered as:

Firefox and Chrome Edge
1/ aaa
1/ bbb
1/ aaa
1/ bbb
1/ aaa
2/ bbb
1/ aaa
1/ bbb

In https://drafts.csswg.org/css-lists/#counter-functions I can't find anything that says that counter() can create a new counter, so it seems Edge is the only one that follows it.

@tabatkins
Copy link
Member

Right, that sort of behavior is definitely not documented. I wasn't aware that it happened, or even remotely believed that it could. ^_^

@Loirooriol
Copy link
Contributor Author

Oh, it seems Firefox and Chrome follow CSS 2.2:

If counter-increment or content on an element or pseudo-element refers to a counter that is not in the scope of any counter-reset, implementations should behave as though a counter-reset had reset the counter to 0 on that element or pseudo-element.

@tabatkins
Copy link
Member

Sigh, cool, I must have missed that when I was drafting the Lists spec.

@fantasai
Copy link
Collaborator

Fixed see 09f1d2b and 848b8c6 and maybe a few changesets in between

@fantasai
Copy link
Collaborator

Marked Obvious Bugfix since we're supposed to be in sync with CSS2.1

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

3 participants