::part()
Quick Summary for ::part
The
::part
CSS pseudo-element represents any element within a shadow tree that has a matching part
attribute.
Code Usage for ::part
custom-element::part(foo) { /* Styles to apply to the `foo` part */ }
More Details for ::part
::part()
The ::part
CSS pseudo-element represents any element within a shadow tree that has a matching part
attribute.
custom-element::part(foo) { /* Styles to apply to the `foo` part */ }
Syntax
::part( <ident>+ )
Examples
HTML
<template id="tabbed-custom-element"> <style type="text/css"> *, ::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
tabbed-custom-element::part(tab) { color: #0c0dcc; border-bottom: transparent solid 2px; } tabbed-custom-element::part(tab):hover { background-color: #0c0d19; border-color: #0c0d33; } tabbed-custom-element::part(tab):hover:active { background-color: #0c0d33; } tabbed-custom-element::part(tab):focus { box-shadow: 0 0 0 1px #0a84ff inset, 0 0 0 1px #0a84ff, 0 0 0 4px rgba(10, 132, 255, 0.3); } tabbed-custom-element::part(active) { color: #0060df; border-color: #0a84ff !important; }
JavaScript
let template = document.querySelector("#tabbed-custom-element"); globalThis.customElements.define(template.id, class extends HTMLElement { constructor() { super(); this.attachShadow({ mode: "open" }); this.shadowRoot.appendChild(template.content); } });
Result
Specifications
Specification |
---|
CSS Shadow Parts # part |
See also
Thepart
attribute - Used to define parts which can be selected by the ::part()
selector The exportparts
attribute - Used to transitively export shadow parts from a nested shadow tree into a containing light tree. Explainer: CSS Shadow ::part and ::theme Last modified: Aug 12, 2021, by MDN contributors
Select your preferred language English (US)Français日本語中文 (简体) Change language Posted in
12:22 am, February 22, 2022
Add Comment
Other Items in CSS
rgb()
rgba()
:right
right
@right-bottom
:root
rotate
rotate()
rotate3d()
rotateX()
rotateY()
rotateZ()
row-gap
ruby-align
ruby-position
saturate()
scale
scale()
scale3d()
scaleX()
scaleY()
scaleZ()
:scope
scroll-behavior
scroll-margin
scroll-margin-block
scroll-margin-block-end
scroll-margin-block-start
scroll-margin-bottom
scroll-margin-inline
scroll-margin-inline-end
scroll-margin-inline-start
scroll-margin-left
scroll-margin-right
scroll-margin-top
scroll-padding
scroll-padding-block
scroll-padding-block-end
scroll-padding-block-start
scroll-padding-bottom
scroll-padding-inline
scroll-padding-inline-end
scroll-padding-inline-start
scroll-padding-left
scroll-padding-right
scroll-padding-top
scroll-snap-align
scroll-snap-stop
scroll-snap-type
@scroll-timeline