:defined
Baseline
Widely available
This feature is well established and works across many devices and browser versions. Itâs been available across browsers since 2020ë 1ì.
CSS :defined ìì¬ í´ëì¤ë ì ìë ìì를 ì íí©ëë¤. ì ìë ììë ë¸ë¼ì°ì ì ë´ì¥ë íì¤ ììì, ì±ê³µì ì¼ë¡ ì ì(CustomElementRegistry.define() ë©ìë ë±)í ì¬ì©ì ì§ì ìì를 ì미í©ëë¤.
/* Selects any defined element */
:defined {
font-style: italic;
}
/* Selects any instance of a specific custom element */
simple-custom:defined {
display: block;
}
구문
Error: could not find syntax for this itemìì
>ì ìë기 ì ê¹ì§ ìì ì¨ê¸°ê¸°
ë¤ì ì½ëë ì í¬ì defined-pseudo-class ë°ëª¨ìì ë°ì·í ê²ì ëë¤. (ëì ëª¨ìµ ë³´ê¸°)
ì´ ë°ëª¨ììë ì주 ê°ë¨í ì¬ì©ì ì§ì ìì를 ì ìí©ëë¤.
customElements.define(
"simple-custom",
class extends HTMLElement {
constructor() {
super();
let divElem = document.createElement("div");
divElem.textContent = this.getAttribute("text");
let shadowRoot = this.attachShadow({ mode: "open" }).appendChild(divElem);
}
},
);
ê·¸ í, ìì ìì를 íì¤ <p>ì í¨ê» 문ìì ë£ìµëë¤.
<simple-custom text="Custom element example text"></simple-custom>
<p>Standard paragraph example text</p>
CSSìë ë¤ìì ì¤íì¼ì ìì±í©ëë¤.
// Give the two elements distinctive backgrounds
p {
background: yellow;
}
simple-custom {
background: cyan;
}
// Both the custom and the built-in element are given italic text
:defined {
font-style: italic;
}
ê·¸ë¦¬ê³ ìëì ë ê·ì¹ì íµí´, ì ìëì§ ìì ì¬ì©ì ì§ì ììë ì¨ê¸°ê³ , ì ìê° ì±ê³µì ì¼ë¡ ë ê²½ì°ìë ë¸ë¡ ë 벨 ììë¡ íìí©ëë¤.
simple-custom:not(:defined) {
display: none;
}
simple-custom:defined {
display: block;
}
ìì ë°ëª¨ë íì´ì§ì ë¶ë¬ì¬ ë 꽤 ìê°ì´ 걸릴 ì ìë ë³µì¡í ì¬ì©ì ì§ì ìì ì¤íì¼ë§ì ì ì©íê² ì¸ ì ììµëë¤. ë¡ë©ì´ ìì§ ì§í ì¤ì¼ ë, ì¤íì¼ì ì íì§ ììë 못ì긴 ììê° íì´ì§ì ë ¸ì¶ëë ê²ì ë§ì ì ìì¼ëê¹ì.
ëª ì¸
| Specification |
|---|
| HTML > # selector-defined > |
| Selectors Level 4 > # defined-pseudo > |