Skip to content

[css-nesting] Interaction with :host is unfortunate. #9509

@emilio

Description

@emilio

This test-case (live) doesn't produce the expected behavior (purple) in any browser:

<!doctype html>
<div id="host">Something</div>
<script>
  host.attachShadow({ mode: "open" }).innerHTML = `
    <style>
      :host {
        background-color: green;
      }
      div {
        background-color: red;
        display: inline-block;
        width: 12px;
        height: 12px;
      }
      :host(#host) div {
        background-color: blue;
      }
      :host(#host) {
        div {
          background-color: purple;
        }
      }
    </style>
    <slot></slot>
    <div></div>
  `;
</script>

This is because per spec, the host only matches featureless :host selectors, and the & (or :is(:host(..)) for that matter) isn't that.

This is similar to #9153 / #9492 (cc: #8738).

cc: @tabatkins @andruud @mdubet @LeaVerou @fantasai

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-nesting-1Current Work

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions