b1gc8v 发表于 2024-6-30 10:48:01

前端-CSS选取器(总)


    <h2 style="color: black; text-align: left; margin-bottom: 10px;">前言</h2>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> 各大浏览器都定义了私有属性,以便让用户体验CSS3的新特性。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> 例如WebKit类型的浏览器 , 如Safari,Chrome 私有属性以-moz-前缀<span style="color: black;">起始</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> Konqueror类型的浏览器的私有属性是以-kt t m-l 前缀<span style="color: black;">起始</span></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"> Opera浏览器的私有属性是-o-前缀<span style="color: black;">起始</span></p>Internet Explorer 浏览器是以-ms-<span style="color: black;">起始</span>(IE8+)
    <h2 style="color: black; text-align: left; margin-bottom: 10px;">本篇博客学习重点</h2><span style="color: black;">认识</span>CSS<span style="color: black;">选取</span>器<span style="color: black;">运用</span>组合<span style="color: black;">选取</span>器<span style="color: black;">把握</span>属性<span style="color: black;">选取</span>器和伪类<span style="color: black;">选取</span>器的<span style="color: black;">运用</span><span style="color: black;">办法</span>
    <h2 style="color: black; text-align: left; margin-bottom: 10px;">知识点-CSS<span style="color: black;">选取</span>器</h2>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://pic3.zhimg.com/80/v2-b92a8dc131bf26a64c7ef4526ae15436_720w.webp" style="width: 50%; margin-bottom: 20px;"></div>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://pic3.zhimg.com/80/v2-24b67b5b2d67b718c035dfffa6c8479e_720w.webp" style="width: 50%; margin-bottom: 20px;"></div>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://pic3.zhimg.com/80/v2-1ce10b846b9392d92e8c3ff8ccf6f302_720w.webp" style="width: 50%; margin-bottom: 20px;"></div>
    <h3 style="color: black; text-align: left; margin-bottom: 10px;">1 兄弟<span style="color: black;">选取</span>器</h3>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">经过</span><span style="color: black;">浪花</span>号(~)分隔符进行定义</p>兄弟<span style="color: black;">选取</span>器<span style="color: black;">选取</span>前置元素后同级的所有匹配元素
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">代码</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"> <span style="color: black;">&lt;</span><span style="color: black;">body</span><span style="color: black;">&gt;</span>
      <span style="color: black;">&lt;!-- 兄弟<span style="color: black;">选取</span>器 --&gt;</span>
      <span style="color: black;">&lt;</span><span style="color: black;">style</span><span style="color: black;">&gt;</span>
      <span style="color: black;">p</span> <span style="color: black;">~</span> <span style="color: black;">span</span><span style="color: black;">{</span>
      <span style="color: black;">bac<span style="color: black;">公斤</span>round</span><span style="color: black;">:</span> <span style="color: black;">red</span><span style="color: black;">;</span>
      <span style="color: black;">display</span><span style="color: black;">:</span> <span style="color: black;">block</span><span style="color: black;">;</span>
      <span style="color: black;">margin-top</span><span style="color: black;">:</span> <span style="color: black;">10</span><span style="color: black;">px</span><span style="color: black;">;</span>
      <span style="color: black;">}</span>
      <span style="color: black;">&lt;/</span><span style="color: black;">style</span><span style="color: black;">&gt;</span>
      <span style="color: black;">&lt;</span><span style="color: black;">p</span><span style="color: black;">&gt;</span>hjhj<span style="color: black;">&lt;/</span><span style="color: black;">p</span><span style="color: black;">&gt;</span>
      <span style="color: black;">&lt;</span><span style="color: black;">span</span><span style="color: black;">&gt;</span>dnmd1<span style="color: black;">&lt;/</span><span style="color: black;">span</span><span style="color: black;">&gt;</span>
      <span style="color: black;">&lt;</span><span style="color: black;">span</span><span style="color: black;">&gt;</span>dnmd2<span style="color: black;">&lt;/</span><span style="color: black;">span</span><span style="color: black;">&gt;</span>
      <span style="color: black;">&lt;</span><span style="color: black;">div</span><span style="color: black;">&gt;</span>fff<span style="color: black;">&lt;/</span><span style="color: black;">div</span><span style="color: black;">&gt;</span>
      <span style="color: black;">&lt;</span><span style="color: black;">span</span><span style="color: black;">&gt;</span>dnmd3<span style="color: black;">&lt;/</span><span style="color: black;">span</span><span style="color: black;">&gt;</span>
      <span style="color: black;">&lt;</span><span style="color: black;">span</span><span style="color: black;">&gt;</span>dnmd4<span style="color: black;">&lt;/</span><span style="color: black;">span</span><span style="color: black;">&gt;</span>
      <span style="color: black;">&lt;</span><span style="color: black;">span</span><span style="color: black;">&gt;</span>dnmd5<span style="color: black;">&lt;/</span><span style="color: black;">span</span><span style="color: black;">&gt;</span>
      <span style="color: black;">&lt;/</span><span style="color: black;">body</span><span style="color: black;">&gt;</span>
    </div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">效果</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://pic4.zhimg.com/80/v2-bba7e3d2e7e7c648901f47ce510c972f_720w.webp" style="width: 50%; margin-bottom: 20px;"></div>
    <h3 style="color: black; text-align: left; margin-bottom: 10px;">2 属性<span style="color: black;">选取</span>器</h3>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">以中括号<span style="color: black;">做为</span>语法标识符,在中括号中科院<span style="color: black;">包括</span>HTML属性名<span style="color: black;">或</span>属性值,<span style="color: black;">经过</span>^$|等运算符,定义<span style="color: black;">区别</span>形式的属性<span style="color: black;">选取</span>器,语法如下:</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;">[属性<span style="color: black;">选取</span>符]</div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">CSS3的属性<span style="color: black;">选取</span>器<span style="color: black;">重点</span><span style="color: black;">包含</span>以下几种</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://pic3.zhimg.com/80/v2-efe1d1dc257c6e2af755ec87ba0a63aa_720w.webp" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">例</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"> <span style="color: black;">&lt;</span><span style="color: black;">body</span><span style="color: black;">&gt;</span>
      <span style="color: black;">&lt;!-- 属性<span style="color: black;">选取</span>器 --&gt;</span>
      <span style="color: black;">&lt;</span><span style="color: black;">style</span><span style="color: black;">&gt;</span>
      <span style="color: black;">/* 匹配属性 */</span>
      <span style="color: black;">a</span><span style="color: black;">[</span><span style="color: black;">href</span><span style="color: black;">]</span> <span style="color: black;">{</span>
      <span style="color: black;">bac<span style="color: black;">公斤</span>round</span><span style="color: black;">:</span> <span style="color: black;">red</span><span style="color: black;">;</span>
      <span style="color: black;">color</span><span style="color: black;">:</span> <span style="color: black;">white</span><span style="color: black;">;</span>
      <span style="color: black;">}</span>

      <span style="color: black;">/* 匹配属性值 */</span>
      <span style="color: black;">input</span><span style="color: black;">[</span><span style="color: black;">type</span><span style="color: black;">=</span><span style="color: black;">text</span><span style="color: black;">]</span> <span style="color: black;">{</span>
      <span style="color: black;">bac<span style="color: black;">公斤</span>round</span><span style="color: black;">:</span> <span style="color: black;">red</span><span style="color: black;">;</span>
      <span style="color: black;">color</span><span style="color: black;">:</span> <span style="color: black;">white</span><span style="color: black;">;</span>
      <span style="color: black;">}</span>

      <span style="color: black;">/* 匹配空白 */</span>
      <span style="color: black;">ul</span> <span style="color: black;">li</span><span style="color: black;">[</span><span style="color: black;">class</span><span style="color: black;">~=</span><span style="color: black;">t</span><span style="color: black;">]</span> <span style="color: black;">{</span>
      <span style="color: black;">bac<span style="color: black;">公斤</span>round</span><span style="color: black;">:</span> <span style="color: black;">blue</span><span style="color: black;">;</span>
      <span style="color: black;">}</span>

      <span style="color: black;">ul</span> <span style="color: black;">li</span><span style="color: black;">[</span><span style="color: black;">class</span><span style="color: black;">=</span><span style="color: black;">s</span><span style="color: black;">]</span> <span style="color: black;">{</span>
      <span style="color: black;">bac<span style="color: black;">公斤</span>round</span><span style="color: black;">:</span> <span style="color: black;">red</span><span style="color: black;">;</span>
      <span style="color: black;">}</span>

      <span style="color: black;">ul</span> <span style="color: black;">li</span><span style="color: black;">[</span><span style="color: black;">class</span><span style="color: black;">=</span><span style="color: black;">f</span><span style="color: black;">]</span> <span style="color: black;">{</span>
      <span style="color: black;">bac<span style="color: black;">公斤</span>round</span><span style="color: black;">:</span> <span style="color: black;">yellow</span><span style="color: black;">;</span>
      <span style="color: black;">}</span>

      <span style="color: black;">/* 匹配连字符 */</span>
      <span style="color: black;">ol</span> <span style="color: black;">li</span><span style="color: black;">[</span><span style="color: black;">class</span><span style="color: black;">|=</span><span style="color: black;">f</span><span style="color: black;">]</span> <span style="color: black;">{</span>
      <span style="color: black;">bac<span style="color: black;">公斤</span>round</span><span style="color: black;">:</span> <span style="color: black;">blue</span><span style="color: black;">;</span>
      <span style="color: black;">}</span>

      <span style="color: black;">/* 匹配前缀 */</span>
      <span style="color: black;">p</span><span style="color: black;">[</span><span style="color: black;">title</span><span style="color: black;">^=</span><span style="color: black;">hello</span><span style="color: black;">]</span> <span style="color: black;">{</span>
      <span style="color: black;">font-size</span><span style="color: black;">:</span> <span style="color: black;">40</span><span style="color: black;">px</span><span style="color: black;">;</span>
      <span style="color: black;">}</span>

      <span style="color: black;">/* 匹配后缀 */</span>
      <span style="color: black;">p</span><span style="color: black;">[</span><span style="color: black;">title</span><span style="color: black;">$=</span><span style="color: black;">good</span><span style="color: black;">]</span> <span style="color: black;">{</span>
      <span style="color: black;">font-size</span><span style="color: black;">:</span> <span style="color: black;">40</span><span style="color: black;">px</span><span style="color: black;">;</span>
      <span style="color: black;">}</span>
      <span style="color: black;">&lt;/</span><span style="color: black;">style</span><span style="color: black;">&gt;</span>
      <span style="color: black;">&lt;!-- 匹配属性 --&gt;</span>
      <span style="color: black;">&lt;</span><span style="color: black;">a</span> <span style="color: black;">href</span><span style="color: black;">=</span><span style="color: black;">"#"</span><span style="color: black;">&gt;</span>baidu<span style="color: black;">&lt;/</span><span style="color: black;">a</span><span style="color: black;">&gt;</span>
      <span style="color: black;">&lt;!-- 匹配属性值 --&gt;</span>
      <span style="color: black;">&lt;</span><span style="color: black;">p</span><span style="color: black;">&gt;</span>
      <span style="color: black;">&lt;</span><span style="color: black;">input</span> <span style="color: black;">type</span><span style="color: black;">=</span><span style="color: black;">"text"</span> <span style="color: black;">name</span><span style="color: black;">=</span><span style="color: black;">"checkbox"</span> <span style="color: black;">value</span><span style="color: black;">=</span><span style="color: black;">"cao"</span> <span style="color: black;">/&gt;</span>
      <span style="color: black;">&lt;/</span><span style="color: black;">p</span><span style="color: black;">&gt;</span>
      <span style="color: black;">&lt;!-- 匹配空白 --&gt;</span>
      <span style="color: black;">&lt;</span><span style="color: black;">ul</span><span style="color: black;">&gt;</span>
      <span style="color: black;">&lt;</span><span style="color: black;">li</span> <span style="color: black;">class</span><span style="color: black;">=</span><span style="color: black;">"f"</span><span style="color: black;">&gt;</span>f<span style="color: black;">&lt;/</span><span style="color: black;">li</span><span style="color: black;">&gt;</span>
      <span style="color: black;">&lt;</span><span style="color: black;">li</span> <span style="color: black;">class</span><span style="color: black;">=</span><span style="color: black;">"s"</span><span style="color: black;">&gt;</span>s<span style="color: black;">&lt;/</span><span style="color: black;">li</span><span style="color: black;">&gt;</span>
      <span style="color: black;">&lt;</span><span style="color: black;">li</span> <span style="color: black;">class</span><span style="color: black;">=</span><span style="color: black;">"t"</span><span style="color: black;">&gt;</span>t<span style="color: black;">&lt;/</span><span style="color: black;">li</span><span style="color: black;">&gt;</span>
      <span style="color: black;">&lt;</span><span style="color: black;">li</span> <span style="color: black;">class</span><span style="color: black;">=</span><span style="color: black;">"f s"</span><span style="color: black;">&gt;</span>f<span style="color: black;">&lt;/</span><span style="color: black;">li</span><span style="color: black;">&gt;</span>
      <span style="color: black;">&lt;</span><span style="color: black;">li</span> <span style="color: black;">class</span><span style="color: black;">=</span><span style="color: black;">"f f"</span><span style="color: black;">&gt;</span>f<span style="color: black;">&lt;/</span><span style="color: black;">li</span><span style="color: black;">&gt;</span>
      <span style="color: black;">&lt;</span><span style="color: black;">li</span> <span style="color: black;">class</span><span style="color: black;">=</span><span style="color: black;">"s t"</span><span style="color: black;">&gt;</span>f<span style="color: black;">&lt;/</span><span style="color: black;">li</span><span style="color: black;">&gt;</span>
      <span style="color: black;">&lt;</span><span style="color: black;">li</span> <span style="color: black;">class</span><span style="color: black;">=</span><span style="color: black;">"s t f"</span><span style="color: black;">&gt;</span>f<span style="color: black;">&lt;/</span><span style="color: black;">li</span><span style="color: black;">&gt;</span>
      <span style="color: black;">&lt;/</span><span style="color: black;">ul</span><span style="color: black;">&gt;</span>
      <span style="color: black;">&lt;!-- 匹配连字符 --&gt;</span>
      <span style="color: black;">&lt;</span><span style="color: black;">ol</span><span style="color: black;">&gt;</span>
      <span style="color: black;">&lt;</span><span style="color: black;">li</span> <span style="color: black;">class</span><span style="color: black;">=</span><span style="color: black;">"f"</span><span style="color: black;">&gt;</span>f<span style="color: black;">&lt;/</span><span style="color: black;">li</span><span style="color: black;">&gt;</span>
      <span style="color: black;">&lt;</span><span style="color: black;">li</span> <span style="color: black;">class</span><span style="color: black;">=</span><span style="color: black;">"s"</span><span style="color: black;">&gt;</span>s<span style="color: black;">&lt;/</span><span style="color: black;">li</span><span style="color: black;">&gt;</span>
      <span style="color: black;">&lt;</span><span style="color: black;">li</span> <span style="color: black;">class</span><span style="color: black;">=</span><span style="color: black;">"t"</span><span style="color: black;">&gt;</span>t<span style="color: black;">&lt;/</span><span style="color: black;">li</span><span style="color: black;">&gt;</span>
      <span style="color: black;">&lt;</span><span style="color: black;">li</span> <span style="color: black;">class</span><span style="color: black;">=</span><span style="color: black;">"f-s"</span><span style="color: black;">&gt;</span>f<span style="color: black;">&lt;/</span><span style="color: black;">li</span><span style="color: black;">&gt;</span>
      <span style="color: black;">&lt;</span><span style="color: black;">li</span> <span style="color: black;">class</span><span style="color: black;">=</span><span style="color: black;">"s-t"</span><span style="color: black;">&gt;</span>f<span style="color: black;">&lt;/</span><span style="color: black;">li</span><span style="color: black;">&gt;</span>
      <span style="color: black;">&lt;</span><span style="color: black;">li</span> <span style="color: black;">class</span><span style="color: black;">=</span><span style="color: black;">"s-t-f"</span><span style="color: black;">&gt;</span>f<span style="color: black;">&lt;/</span><span style="color: black;">li</span><span style="color: black;">&gt;</span>
      <span style="color: black;">&lt;/</span><span style="color: black;">ol</span><span style="color: black;">&gt;</span>
      <span style="color: black;">&lt;!-- 匹配前缀 --&gt;</span>
      <span style="color: black;">&lt;</span><span style="color: black;">p</span> <span style="color: black;">title</span><span style="color: black;">=</span><span style="color: black;">"hello"</span><span style="color: black;">&gt;</span>hello<span style="color: black;">&lt;/</span><span style="color: black;">p</span><span style="color: black;">&gt;</span>
      <span style="color: black;">&lt;</span><span style="color: black;">p</span> <span style="color: black;">title</span><span style="color: black;">=</span><span style="color: black;">"ghello2"</span><span style="color: black;">&gt;</span>hello2<span style="color: black;">&lt;/</span><span style="color: black;">p</span><span style="color: black;">&gt;</span>
      <span style="color: black;">&lt;</span><span style="color: black;">p</span> <span style="color: black;">title</span><span style="color: black;">=</span><span style="color: black;">"hello3gggs"</span><span style="color: black;">&gt;</span>hello3<span style="color: black;">&lt;/</span><span style="color: black;">p</span><span style="color: black;">&gt;</span>
      <span style="color: black;">&lt;!-- 匹配后缀 --&gt;</span>
      <span style="color: black;">&lt;</span><span style="color: black;">p</span> <span style="color: black;">title</span><span style="color: black;">=</span><span style="color: black;">"good"</span><span style="color: black;">&gt;</span>good<span style="color: black;">&lt;/</span><span style="color: black;">p</span><span style="color: black;">&gt;</span>
      <span style="color: black;">&lt;</span><span style="color: black;">p</span> <span style="color: black;">title</span><span style="color: black;">=</span><span style="color: black;">"ghellogood"</span><span style="color: black;">&gt;</span>good2<span style="color: black;">&lt;/</span><span style="color: black;">p</span><span style="color: black;">&gt;</span>
      <span style="color: black;">&lt;</span><span style="color: black;">p</span> <span style="color: black;">title</span><span style="color: black;">=</span><span style="color: black;">"goodgggs"</span><span style="color: black;">&gt;</span>good3<span style="color: black;">&lt;/</span><span style="color: black;">p</span><span style="color: black;">&gt;</span>
      <span style="color: black;">&lt;/</span><span style="color: black;">body</span><span style="color: black;">&gt;</span>
    </div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">效果</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://pic2.zhimg.com/80/v2-4b4952150e05b234af6c6661e712681d_720w.webp" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">详细</span>案例</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://pic2.zhimg.com/80/v2-0ba1657e2c055f3af0ada8ca0d684b55_720w.webp" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">待续...(2022/2/28)</p>




页: [1]
查看完整版本: 前端-CSS选取器(总)