Skip to content

Commit

Permalink
Merge branch 'main' into 35720-Implement-interactive-widget
Browse files Browse the repository at this point in the history
  • Loading branch information
dletorey authored Dec 2, 2024
2 parents 858c9e6 + f47d719 commit f89f3b4
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 1 deletion.
75 changes: 75 additions & 0 deletions files/en-us/web/css/_colon_has-slotted/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
---
title: ":has-slotted"
slug: Web/CSS/:has-slotted
page-type: css-pseudo-class
browser-compat: css.selectors.has-slotted
---

{{CSSRef}}

The **`:has-slotted`** [CSS](/en-US/docs/Web/CSS) [pseudo-class](/en-US/docs/Web/CSS/Pseudo-classes) matches when the content of a {{HTMLElement("slot")}} element is not empty or not using the default value (see [Using templates and slots](/en-US/docs/Web/API/Web_components/Using_templates_and_slots) for more information).

> [!NOTE] Even a single whitespace text node is sufficient to make `:has-slotted` apply.
This only works when used inside CSS placed within a [shadow DOM](/en-US/docs/Web/API/Web_components/Using_shadow_DOM).

```css
/* Selects the content of a <slot> element that has content that is not default */
:has-slotted {
color: green;
}

/* Selects the content of a <slot> element that has no content or default */
:not(:has-slotted) {
color: red;
}
```

## Syntax

```css-nolint
:has-slotted {
/* ... */
}
```

## Examples

This example has two `<slot>` elements, one of which has been assigned some content and the other has not.

### HTML

```html
<p>
<template shadowrootmode="open">
<style>
:has-slotted {
color: rebeccapurple;
}
</style>
<slot name="one">Placeholder 1</slot>
<slot name="two">Placeholder 2</slot>
</template>
<span slot="one">Slotted content</span>
</p>
```

### Result

The `<slot>` element that has been assigned content matched the `:has-slotted` pseudo-class and has the `color` value of `rebbecapurple` applied.

{{EmbedLiveSample("simple_example",100,300)}}

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- HTML {{HTMLElement("template")}} element
- HTML {{HTMLElement("slot")}} element
- {{CSSXRef("::slotted")}}
1 change: 1 addition & 0 deletions files/en-us/web/css/_doublecolon_slotted/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ Our markup includes three custom elements, including a custom element with an in
- {{cssxref(":host")}}
- {{cssxref(":host_function", ":host()")}}
- {{cssxref(":host-context", ":host-context()")}}
- {{cssxref(":has-slotted")}}
- [CSS scoping](/en-US/docs/Web/CSS/CSS_scoping) module
- HTML [`slot`](/en-US/docs/Web/HTML/Global_attributes/slot) attribute
- HTML {{HTMLElement("slot")}} element
Expand Down
1 change: 1 addition & 0 deletions files/en-us/web/html/element/slot/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,5 @@ This element includes the [global attributes](/en-US/docs/Web/HTML/Global_attrib
- HTML {{HTMLElement("template")}} element
- HTML [`slot`](/en-US/docs/Web/HTML/Global_attributes/slot) attribute
- CSS {{CSSXref("::slotted")}} pseudo-element
- CSS {{cssxref(":has-slotted")}} pseudo-class
- [CSS scoping](/en-US/docs/Web/CSS/CSS_scoping) module
2 changes: 1 addition & 1 deletion files/en-us/web/html/element/template/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ Since `firstClone` is a `DocumentFragment`, only its children are added to `cont

- [`part`](/en-US/docs/Web/HTML/Global_attributes/part) and [`exportparts`](/en-US/docs/Web/HTML/Global_attributes/exportparts) HTML attributes
- {{HTMLElement("slot")}} HTML element
- {{CSSXref(":host")}}, {{CSSXref(":host_function", ":host()")}}, and {{CSSXref(":host-context", ":host-context()")}} CSS pseudo-classes
- {{CSSXref(":has-slotted")}}, {{CSSXref(":host")}}, {{CSSXref(":host_function", ":host()")}}, and {{CSSXref(":host-context", ":host-context()")}} CSS pseudo-classes
- {{CSSXref("::part")}} and {{CSSXref("::slotted")}} CSS pseudo-elements
- [`ShadowRoot`](/en-US/docs/Web/API/ShadowRoot) interface
- [Using templates and slots](/en-US/docs/Web/API/Web_components/Using_templates_and_slots)
Expand Down

0 comments on commit f89f3b4

Please sign in to comment.