# css_scope
# :scope属于 css 伪类,它表示作为选择器要匹配的参考点元素
/* 当前的:scope 等效于 :root */
:scope {
background-color: lime;
}
当从 DOM API 使用,如:querySelector(), querySelectorAll(), metchees()或Element.closet(),:scope匹配你调用的 API 元素
let paragraph = document.getElementById("para");
let output = document.getElementById("output");
if (paragraph.matches(":scope")) {
output.innerText = "Yep. the element is its own scope as expected!";
}
← CSS 与数学 scss 和 less →