2.4.1 樣式表定義語法 HTML
樣式表:也稱樣式定義,或樣式規(guī)則,可包含于文檔中,也可保存于.css文件中。基本結(jié)構(gòu)為:
Selector{property1:value1;property2:value2;property3:value3;……}
Selector定義樣式作用的對(duì)象,稱為選擇器,花括號(hào)中為樣式聲明塊,其中property為CSS屬性,value為屬性對(duì)應(yīng)的值,各樣式聲明之間用分號(hào)隔開。
常用Selector類型
HTML標(biāo)記符
用戶定義的類
用戶定義的ID
偽類
HTML Selector
不帶尖括號(hào)的標(biāo)記名作選擇符
HTML標(biāo)記符是最常用的selector,它重新定義了HTML標(biāo)記符的顯示效果。例如:
H1{text-align:center;color:red}
使所有用H1標(biāo)記符修飾的內(nèi)容都居中和用紅色顯示
body,ul,ol,li,p,h1,h2,h3,h4,h5,h6,form,fieldset,table,td,img,div{margin:0;padding:0;border:0;}
ul,ol{list-style-type:none;}
選擇符應(yīng)用示例基本清單
<html>
<head>
<title>New Port Richey</title>
<style type="text/css">
* { font-family: Verdana }
</style>
</head>
<body>
<h2 align="center">The New Port Richey Dog Show</h2>
<h4 align="center">Show Date: 7/31/2001</h4>
<h4 align="center">New Port Richey, FL</h4>
<p align="center">
<span class="category">Best In Show:</span>
<span id="bestinshow">CH Sarah's Razzle Dazzle (Yorkshire Terrier)</span>
</p>
<p>
<a href="complete">Complete results</a>
</p>
<table align="center">
<tr>
<td class="category">
<a href="herding.html">Herding Group:</a></td>
<td>German Shepherd Dog</td>
<td>CH Sabre Dawn</td> </tr>
<tr>
<td class="category">
<a href="toy.html">Toy Group:</a> </td>
<td>Yorkshire Terrier</td>
<td>CH Sarah's Razzle Dazzle</td> </tr>
<tr>
<td class="category">
<a href="sporting.html">Sporting Group:</a> </td>
<td>Golden Retriever</td>
<td>CH Chase's Golden Chance</td> </tr>
<tr>
<td class="category">
<a href="nonsporting.html">Non-Sporting Group:</a> </td>
<td>Tibetan Terrier</td>
<td>CH Winston of Sunny Brook Lane</td> </tr> </table>
</body>
</html>
選擇符應(yīng)用示例基本清單代碼運(yùn)行頁面
標(biāo)記選擇符應(yīng)用示例清單
...
<style type="text/css">
* { font-family: Verdana }
td { font-size: 10pt }
</style>
...
點(diǎn)擊加載更多評(píng)論>>