Skip to content

[selectors][css-content] :level(an+b) Pseudo Class #351

Closed
@Crissov

Description

@Crissov

The generation of bookmark levels has been discussed e.g. in #204 and in November 2015 on www-style. @frivoal had shown that it’s nearly impossible to recreate the HTML5 outline algorithm with existing Selectors, so bookmark-level: auto would make some sense. That value hasn’t been added to the drafts, though, and I would like to propose a different solution, a new structural pseudo-class.

Nesting, stacking or hierarchy levels are of interest for styling in several cases, e.g. headings or sections and lists in document markup languages or layers and sprites in images. So let there be an abstract level that depends on the host language and may differ among its element types. Since a pseudo class increases specifity, the following rulesets should sufficiently describe the usually desired behavior for HTML:

* { bookmark-level: none; }
h1 { bookmark-level: 1; }
h2 { bookmark-level: 2; }
h3 { bookmark-level: 3; }
h4 { bookmark-level: 4; }
h5 { bookmark-level: 5; }
h6 { bookmark-level: 6; }
h1:level(0), h2:level(0), h3:level(0), h4:level(0), h5:level(0), h6:level(0)
  { bookmark-level: none; }
h2:level(1), h3:level(1), h4:level(1), h5:level(1), h6:level(1)
  { bookmark-level: 1; }
h1:level(2), h3:level(2), h4:level(2), h5:level(2), h6:level(2)
  { bookmark-level: 2; }
h1:level(3), h2:level(3), h4:level(3), h5:level(3), h6:level(3)
  { bookmark-level: 3; }
h1:level(4), h2:level(4), h3:level(4), h5:level(4), h6:level(4)
  { bookmark-level: 4; }
h1:level(5), h2:level(5), h3:level(5), h4:level(5), h6:level(5)
  { bookmark-level: 5; }
h1:level(6), h2:level(6), h3:level(6), h4:level(6), h5:level(6)
  { bookmark-level: 6; }

The syntax inside parentheses would probably follow the existing an+b syntax, but I‘m not sure we’d need to differentiate :first-level, :last-level and :nth-level(), but it would be consistent.

Likewise, one could easily ensure the same marker style for items in nested lists, no matter if the structure mixes ol, ul and dl.

ul>li:level(2) { list-style-type: disc; }

PS: Since this is a more generic pseudo class than rather semantic :heading-level() (which I think I had proposed unsuccessfully several years ago), the following would not be sufficient for HTML:

:level(1) { bookmark-level: 1; }
:level(2) { bookmark-level: 2; }
:level(3) { bookmark-level: 3; }
:level(4) { bookmark-level: 4; }
:level(5) { bookmark-level: 5; }
:level(6) { bookmark-level: 6; }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions