A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.cdn.mozilla.net/en-US/docs/Web/CSS/CSS_nesting/Nesting_and_specificity below:

CSS nesting and specificity - CSS

CSS nesting and specificity

The specificity of the & nesting selector is calculated using the largest specificity in the associated selector list. This is identical to how specificity is calculated when using the :is() function.

<b class="foo">
  <i>Blue text</i>
</b>
& nesting syntax
#a, b {
  & i {
    color: blue;
  }
}

.foo i {
  color: red;
}
:is() syntax
:is(#a, b) {
  & i {
    color: blue;
  }
}

.foo i {
  color: red;
}

In this example, the id selector (#a) has a specificity of 1-0-0, while the type selector (b) has a specificity of 0-0-1. The & nesting selector and :is() pseudo-class both take a specificity of 1-0-0, even though the #a id selector is never used.

The .foo class selector has a specificity of 0-1-0. This makes the total specificity 1-0-1 for & i and 0-1-1 for .foo i, meaning that color: blue; wins out.

See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4