使用 CSS(樣式表)的 class

來源:互聯網
上載者:User
class 是類,用來定義 style 屬性。
在使用 CSS(樣式表)時用 class 可以更方便。
舉例:
檔案1:C1.CSS
.Bar
{
border-right: 2px outset;
border-top: 2px outset;
overflow: auto;
border-left: 2px outset;
border-bottom: 2px outset;
}
.BCap
{
color: graytext;
}

.BDroper
{
border-right: 2px outset;
border-top: 2px outset;
border-left: 2px outset;
width: 1px;
cursor: move;
border-bottom: 2px outset;
position: static;
height: 100%;
}

這個檔案定義了三個類(class):
Bar 工具列的樣式
BCap 工具列標題的樣式
BDroper 工具列拖動按鈕的樣式

檔案2:Main.HTM (HTML)
<HTML>
<HEAD>
<LINK href="C1.CSS" type=text/css rel=stylesheet> <!--樣式表的路徑-->
</HEAD>
<BODY>
<DIV class="Bar">
<a class="BDroper"></a>
<a class="BDroper"></a>
  
<a class="BCap">瀏覽</a>
<a href="javascript:history.back(1)">返回</a>
<a href="javascript:history.forward(1)">前進</a>
</DIV>
<BODY>
</HTML>

如果不是用樣式表,檔案2的內容如下:
<HTML>
<HEAD>
<!--沒有樣式表-->
</HEAD>
<BODY>
<DIV style="border-right: 2px outset; border-top: 2px outset; overflow: auto; border-left: 2px outset; border-bottom: 2px outset;">
<a style="border-right: 2px outset; border-top: 2px outset; border-left: 2px outset; width: 1px; cursor: move; border-bottom: 2px outset; position: static; height: 100%;"></a>
<a style="border-right: 2px outset; border-top: 2px outset; border-left: 2px outset; width: 1px; cursor: move; border-bottom: 2px outset; position: static; height: 100%;"></a>
  
<a style="color: graytext;">瀏覽</a>
<a href="javascript:history.back(1)">返回</a>
<a href="javascript:history.forward(1)">前進</a>
</DIV>
<BODY>
</HTML>

可見,如果使用樣式表以及 class 屬性,則對於樣式的定義就能簡單的多。
<a href="index.jsp" class="atop">
這定義了一個超連結,它的類為 atop。如果你能找到這個網頁的樣式表,你會找到這個類的定義。也許是這樣的:
.atop
{
.....
}

當然,一個網頁也可以使用多個樣式表:
...
<HEAD>
<LINK href="C1.CSS" type=text/css rel=stylesheet> <!--樣式表1的路徑-->
<LINK href="../C2.CSS" type=text/css rel=stylesheet> <!--樣式表2的路徑-->
<LINK href="DD1/S1/Main.CSS" type=text/css rel=stylesheet> <!--樣式表3的路徑-->
</HEAD>
... 

相關文章

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.