-
Notifications
You must be signed in to change notification settings - Fork 22.4k
/
index.md
114 lines (89 loc) · 2.13 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
---
title: "::part()"
slug: Web/CSS/::part
page-type: css-pseudo-element
browser-compat: css.selectors.part
---
{{CSSRef}}
The **`::part`** [CSS](/en-US/docs/Web/CSS) [pseudo-element](/en-US/docs/Web/CSS/Pseudo-elements) represents any element within a [shadow tree](/en-US/docs/Web/API/Web_components/Using_shadow_DOM) that has a matching [`part`](/en-US/docs/Web/HTML/Global_attributes#part) attribute.
```css
custom-element::part(foo) {
/* Styles to apply to the `foo` part */
}
```
## Syntax
```css
::part(<ident>+) {
/* ... */
}
```
## Examples
### HTML
```html
<template id="tabbed-custom-element">
<style>
*,
::before,
::after {
box-sizing: border-box;
padding: 1rem;
}
:host {
display: flex;
}
</style>
<div part="tab active">Tab 1</div>
<div part="tab">Tab 2</div>
<div part="tab">Tab 3</div>
</template>
<tabbed-custom-element></tabbed-custom-element>
```
### CSS
```css
tabbed-custom-element::part(tab) {
color: #0c0dcc;
border-bottom: transparent solid 2px;
}
tabbed-custom-element::part(tab):hover {
background-color: #0c0d19;
color: #ffffff;
border-color: #0c0d33;
}
tabbed-custom-element::part(tab):hover:active {
background-color: #0c0d33;
color: #ffffff;
}
tabbed-custom-element::part(tab):focus {
box-shadow:
0 0 0 1px #0a84ff inset,
0 0 0 1px #0a84ff,
0 0 0 4px rgb(10 132 255 / 30%);
}
tabbed-custom-element::part(active) {
color: #0060df;
border-color: #0a84ff !important;
}
```
### JavaScript
```js
let template = document.querySelector("#tabbed-custom-element");
globalThis.customElements.define(
template.id,
class extends HTMLElement {
constructor() {
super().attachShadow({ mode: "open" }).append(template.content);
}
},
);
```
### Result
{{EmbedLiveSample('Examples')}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [`part`](/en-US/docs/Web/HTML/Global_attributes#part) attribute
- {{CSSxRef(":state",":state()")}} pseudo-class function
- [`exportparts`](/en-US/docs/Web/HTML/Global_attributes#exportparts) attribute
- [CSS shadow parts](/en-US/docs/Web/CSS/CSS_shadow_parts) module