Skip to content

[css-cascade-6] clarification of :scope matching in nested scopes #9741

@kizu

Description

@kizu

While testing different ways scopes interact when being nested, and how :scope behaves inside them in both Chrome and Safari Technology Preview, I found a difference in how the browsers treat the :scope when there are nested scopes present.

Here is a CodePen with the example: https://codepen.io/kizu/pen/xxBxKao

HTML & CSS for this example
<div class="outer">
  <div class="inner">
    <div class="test">this should be lightgreen</div>
    <div class="test never">this should be lightgreen</div>
    <div class="test unwrapped">this should be lightgreen</div>
  </div>
</div>
@scope (.outer) {
  .test {
    background: red;
  }
  
  @scope (.inner) {
    :scope.inner .test {
      background: lightgreen;
    }
    
    /* This should never match */
    :scope.outer .test.never {
      background: tomato;
    }
  }
}

@scope (.outer .inner) {
  :scope.inner .unwrapped {
    background: lightgreen;
  }
}

I consider the way it works now in Chrome (the :scope matches the innermost closest defined scope) as correct. I did not find anything in the specs (https://drafts.csswg.org/css-cascade-6/#scope-scope) outside example 8, which shows the scope equivalence, where the :scope matches the inner scoping root.

Given how Safari currently uses the topmost scoping root instead, I think it would be nice to clarify the behavior of the :scope inside nested scopes explicitly in the normative parts of the spec, so there will be less left for interpretation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Closed as Question AnsweredUsed when the issue is more of a question than a problem, and it's been answered.css-cascade-6

    Type

    No type

    Projects

    Status

    Unsorted regular

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions