1. 程式人生 > >html 學習(css class選擇器)

html 學習(css class選擇器)

http://www.jianshu.com/p/802afaab545b

一般情況下,css 根據class修改標籤,js根據id修改標籤。

.A.B.C 與 .A .B .C 與 .A,.B,.C的區別(ABC分別為標籤的class name)

  • .A.B.C 指同時包含三個class的標籤
  • .A .B .C 指在class 為A 的標籤下的class 為B的標籤下的class為C的標籤。(即:按照class 依次向下尋找)
  • .A,.B,.C 指標籤為.A或.B或.C的所有標籤(或關係)
    例如:

    <a href="#" class="one two three"> title one </a
    >
    </br> <a href="#" class="one two"> title two</a>

    以下css 修改了包含class one , class three的所有標籤, 也就是說title one,title two都會被修改

      .one,.three{
        background-color: red;
      }

    以下css修改了同時包含class one, class three的所有標籤,即title one被修改,而title two 沒有變化

      .one.three{
        background-color: red;
      }

    以下css修改了 class 為one下的class為three的標籤, 也就是說title one, title two 都沒有被修改

      .one .three{
      background-color: red;
      }
文/某個胖子(簡書作者)
原文連結:http://www.jianshu.com/p/802afaab545b
著作權歸作者所有,轉載請聯絡作者獲得授權,並標註“簡書作者”。