css 選擇器
選擇器種類
- Attribute selectors
- Class selectors - 常見就不說了
- ID selectors - 常見就不說了
- Type selectors - 常見就不說了
- Universal selectors
Attribute selectors
/* 存在 title 属性的 <a> 元素 */
a[title] {
color: purple;
}
/* 存在 href 属性并且属性值匹配"https://example.org"的 <a> 元素 */
a[href="https://example.org"]
{
color: green;
}
/* 存在 href 属性并且属性值包含"example"的 <a> 元素 */
a[href*="example"] {
font-size: 2em;
}
/* 存在 href 属性并且属性值结尾是".org"的 <a> 元素 */
a[href$=".org"] {
font-style: italic;
}
/* 存在 class 属性并且属性值包含单词"logo"的<a>元素 */
a[class~="logo"] {
padding: 2px;
}