CSS选择器是CSS中用于选择页面元素以应用样式的基本工具。本文提供了一个全面的指南,涵盖了各种选择器和组合器的使用方法。
概述
快速参考
box-sizing: border-box
)。margin-block: 1.5rem
)。.class { text-decoration: underline; }
)。#id { font-family: monospace; }
)。li:has(a) { display: flex; }
)。组合器
header h1
)。header > h1
)。h1 ~ p
)。h1 + p
)。h1, p
)。一般选择器