本篇延續選擇器主題,介紹更進階的屬性選擇器、組合與分組選擇器、後代與兄弟選擇器,以及偽元素選擇器。
<DOCTYPE html>
<html lang="zh-cn">
<head>
<meat charset="gb2312">
<title>還是CSS選擇器</title>
<link rel="stylesheet" type="text/css" href="啦啦啦.css">
</head>
<body>
【b.abc{} 類選擇器,單獨定義 b 標籤】
<b class="abc"> zzhu1i</b>
<span class="abc def">axohs</span>
【[href] 屬性選擇器、超鏈接】
<a href="https://hovertree.com/url/?h=https://www.baidu.com">百度</a>
【[href^="http"]{} 限制開頭是 http】
<a href="https://hovertree.com/url/?h=https://www.baidu.com">百度</a>
【[href$=".cn"]{} 限制結尾是 .cn】
<a href="https://hovertree.com/url/?h=https://www.360.cn">360</a>
【[href*="baidu"]{} 模糊查詢】
<a href="https://hovertree.com/url/?h=https://www.baidu.com">百度</a>
【[class~=""]{} 單獨定義】
【[lang|="en"]{} 匹配帶連字號的屬性值,""裡是橫槓前的內容】
<i lang="en-us">帶橫槓的啊~</i>
【[type="password"] 單獨定義 password、表格】
<input type="text">
<input type="password">
【複合選擇器】
p,b,i,span{}
【分組選擇器】
#abc,.abc,i,span{}
<p id="abc">啦啦啦<b>啦啦啦</b></p>
【後代、派生選擇器】
p b{}
<ul>
<li>兒子
<ol start="2">
<li>孫子</li>
<li>孫子</li>
</ol>
</li>
<li>兒子</li>
<li>兒子</li>
ul li {border:1px solid red} /* 所有 li 都加邊框 */
ul>li {border:1px solid red} /* 只有 ul 直接後代的 li 加邊框 */
</ul>
<p>週五啊~</p>
<b>時間啊~~ </b>
【p + b{} 相鄰兄弟選擇器,匹配 p 之後緊鄰的 b 元素】
【p ~ b{} 普通兄弟選擇器,匹配 p 之後的所有 b 元素】
【偽元素選擇器】
<p>企鵝企鵝企鵝企鵝屋企鵝企鵝企鵝屋鵝企鵝企鵝企鵝屋企鵝企鵝企鵝屋</p>
<div>瀟灑寫啊寫啊寫啊寫啊寫啊寫啊寫啊寫啊寫啊啊啊啊啊啊啊啊啊啊</div>
【首行選定】
div::first-line{}
<p>tiosaioxjao</p>
<span>dqdqiudhq</span>
【塊級首字母改變】
::first-letter{}
<a href="https://hovertree.com/url/?h=https://www.baidu.com">百度</a>
【a::before{ content:"點擊"} 鏈接前插入文字】
【a::after{ content:"搜索"} 鏈接後插入文字】
</body>
</html>