CSS:class選取器的使用,cssclass選取器

來源:互聯網
上載者:User

CSS:class選取器的使用,cssclass選取器

本文介紹css中class選取器的基本用法:為同一個類型的標籤設定屬性。

代碼整理自w3school:http://www.w3school.com.cn

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta http-equiv="Content-Language" content="zh-cn" /><title>class選取器的使用</title><!--在 CSS 中,類別選取器以一個點號顯示。一個類可以被使用多次。--><!--文法:A.B C,如table.blueStyle td    blueStyle:class名;    table:blueStyle只能作為table的屬性;    td:table之下的td標籤的內容將應用blueStyle指定的屬性--><head><style type="text/css">  .redStyle {color: red}  .greenStyleForSpan span {color: green}  table.blueStyle td {background-color:#99f}</style></head><body bgcolor="#eee">  <!--所有擁有redStyle類的html元素都將顯示為紅色-->  <h3>(一)redStyle類被定義在所有的html標籤之上</h3>  <p>我不擁有redStyle類</p>  <p class="redStyle">我是一個p,擁有redStyle類,所以我是紅色的</p>  <h4 class="redStyle">我是一個h4,擁有redStyle類,所以我是紅色的</h4>  <hr/>  <!--和 id 一樣,class 也可被用作派生選取器:-->  <h3>(二)greenStyleForSpan類被定義在所有的html標籤之上並且只對下屬span有效</h3>  <div class="greenStyleForSpan">    <p>我是一個p,我所屬的div具有greenStyleForSpan類。</p>  </div>  <div class="greenStyleForSpan">    <span>我是一個span,我所屬的div具有greenStyleForSpan類。</p>  </div>  <span class="greenStyleForSpan">我是一個span,我自己具有greenStyleForSpan類。</p>  <hr/>  <h3>(三)blueStyle類被定義為table的屬性,並且只有table下屬的td將應用這個屬性。</h3>  <h4>(1)blueStyle類被使用在table上級的div中了,因此table之下的td沒有應用blueStyle屬性</h4>  <div class="blueStyle">    <table cellpadding="10px" border="1">      <tr>        <th>省份</th>        <th>面積</th>      <tr>      <tr>        <td>河南省</th>        <td>16.8</th>      <tr>      <tr>        <td>湖北省</th>        <td>18.1</th>      <tr>    </table>  <div>  <h4>(2)blueStyle類被使用在table中了,因此table之下的td應用了blueStyle屬性,而table之下的p和th則沒有應用這個屬性。</h4>  <table class="blueStyle" cellpadding="10px" border="1">      <p>我是table中的一個p</p>      <tr>        <th>省份</th>        <th>面積</th>      <tr>      <tr>        <td>河南省</th>        <td>16.8</th>      <tr>      <tr>        <td>湖北省</th>        <td>18.1</th>      <tr>    </table></body></html>



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.