Closed Bug 1717772 Opened 5 years ago Closed 5 years ago

counter-reset not working correctly when used with inline style

Categories

(Core :: Layout: Generated Content, Lists, and Counters, defect)

Firefox 89
defect

Tracking

()

RESOLVED INVALID

People

(Reporter: vikash.ckiiita30, Unassigned)

References

Details

Attachments

(3 files)

Attached image counter-rese.png

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0

Steps to reproduce:

  1. Go to https://developer.mozilla.org/en-US/docs/Web/CSS/counter-reset
  2. Select fourth option (counter-reset: chapter-count 5;) from demo section at the top

Actual results:

Preview on the right hand displayed counters as
Chapter 1
Chapter 6
Chapter 2
Chapter 3

Expected results:

Preview on the right hand should display
Chapter 1
Chapter 6
Chapter 7
Chapter 8

Component: Untriaged → Layout: Generated Content, Lists, and Counters
Product: Firefox → Core
Attached file Testcase

Here's that MDN example as a standalone testcase for clarity.

Here's the same example using counters(chapter-count, ".") in the content property.
This makes it a bit easier to see what's going on. The counter-reset: chapter-count 5 on the <h2> opens a nested scope, so the counters inside that element, that its ::before sees, is 1.6.
This is correct because that <h2>'s counter-increment increments the closest scope, which is its own counter which was initialized to 5. The outer scope counter is unaffected.

The next sibling <h2> element after that, uses its parent element's counter scope if it exists (it would only use its previous sibling's scope of there are no ancestor scopes). So it increments the outer scope from 1 to 2.
This is the correct behavior per spec: https://drafts.csswg.org/css-lists-3/#creating-counters
although it has probably changed since this MDN article was written. (see https://github.com/w3c/csswg-drafts/issues/5477 for details)

So, the reported issue is not a bug but the expected behavior for the given testcase.

I'm not sure what the MDN example is trying to illustrate, but it seems a bit confusing to use counter() rather than counters() which would show all the counter scopes. Not sure where to report MDN content problems these days though...

Status: UNCONFIRMED → RESOLVED
Closed: 5 years ago
Resolution: --- → INVALID

(FYI, if you want to set the current scope's counter value you should use counter-set instead.)

Oh, there's a "Report a problem with this content on GitHub" link at the end of that MDN article.
I filed a report to improve the example here: https://github.com/mdn/content/issues/6277

I see same behavior with P tag also, does it also starts a new scope? I am not so sure about that.

Yes, the counter-reset property works exactly the same on all elements.

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: