选择器进阶
子串选择器
a[href^="https"] { color : green;
}
a[href*="example"] { text-decoration : underline;
}
a[href$=".pdf"]::after { content : "📄" ;
}
伪类
状态伪类
a:link { color : blue; }
a:visited { color : purple; }
button:hover { background : #eee; }
input:focus { outline : 2px solid orange; }
结构伪类
ul li:first-child { font-weight : bold; }
ul li:last-child { border-bottom : none; }
ul li:nth-child(3) { color : red; }
tr:nth-child(odd) { background : #f5f5f5; }
伪元素
::before / ::after
h1::before { content : "🌟" ; margin-right : 10px;
}
.price::after { content : "元" ; color : #999;
}
::selection
::selection { background : yellow; color : black;
}
其他选择器
群组选择器
h1, h2, h3 { font-family : Arial;
}
否定伪类
button:not(.disabled) { cursor : pointer;
}