? ?首先疆导,推薦兩本關(guān)于css的書籍驶臊,一本是《css禪意花園》豪治,一本是《精通css:高級web標準解決方案》谆级,兩本都比較適合在初步了解css基本內(nèi)容之后去讀烤礁。第一本講了一些好的布局案例,更偏向于教會如何去設(shè)計完整的頁面肥照,個人認為比較適合在熟練掌握Html+css內(nèi)容后再去讀脚仔;后一本更加詳細的介紹了一些具體的內(nèi)容,如:如何對鏈接應(yīng)用樣式舆绎,對列表 應(yīng)用樣式和創(chuàng)建導(dǎo)航條鲤脏,bug和bug修復(fù)等,但是書中也是有一些錯誤,在應(yīng)用樣式時應(yīng)該注意猎醇。
上周學(xué)習(xí)了對鏈接應(yīng)用樣式窥突、布局、對表單和數(shù)據(jù)表格應(yīng)用樣式硫嘶,這三個內(nèi)容中第一個比較容易波岛,布局在前面的總結(jié)中已經(jīng)有所簡單介紹過,這篇中主要介紹對表單和數(shù)據(jù)表格應(yīng)用樣式音半。
數(shù)據(jù)表格
- 在為表格應(yīng)用樣式前應(yīng)該先有一個較好的HTML文本
<table cellspacing="0" id="playlistTable" summary="Top 15 songs played. Top artists include Cold Play,
Yeah Yeah Yeahs,Snow Patrol,Deeper Water, Kings of Leon,Embrace, Oasis,franz Ferdinand,Jet, The Bees,
Blue States,Kaiser Chiefs and Athlete.">
<caption>Top 15 Playlist</caption>
<colgroup>
<col id="PlaylistCol"/>
<col id="trackCol"/>
<col id="artistCol"/>
<col id="albumCol"/>
</colgroup>
<thead>
<tr>
<th id="playlistPosHead" scop="Col">Playlist Position</th>
<th scope="col">Track Name</th>
<th scope="col">Artist</th>
<th scope="col">Album</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Hide You</td>
<td>Kosheen</td>
<td>Resist</td>
</tr>
<tr>
<td>2</td>
<td>.38.45</td>
<td>Thievery Corporation</td>
<td>Sounds From the Thievery Hi-fi</td>
</tr>
<tr>
<td>3</td>
<td>Fix You</td>
<td>Cold Play</td>
<td>X&Y</td>
</tr>
</tbody>
</table>
這里面有幾個表格特有的元素:
1.summary和caption
- summary應(yīng)用于表格標簽则拷,描述表格內(nèi)容;
- caption用做表格的標題曹鸠。
2.thead煌茬、tbody和foot
- 這個三可以將表格劃分為邏輯部分〕固遥可以將所有列標題放在thead元素中坛善,這樣就可以對這個特殊區(qū)域統(tǒng)一單獨應(yīng)用樣式。如果選擇thead或tfoot元素邻眷,就必須至少使用一個tbody元素眠屎。在一個表格中只能使用一個thead和tfootuansu,但是可以使用多個tbody元素將復(fù)雜的表格劃分為更容易管理的部分肆饶。
3.col和colgroup
- tr能對整行應(yīng)用樣式改衩,但是很難對整列應(yīng)用樣式。colgroup能夠使用col元素定義一個或多個列進行分組驯镊。
接下來就是對表格應(yīng)用樣式了
table{
border-collapse: collapse;
width:50em;
border:1px soid #666;
}
caption{
font-size: 1.2em;
font-weight: bold;
margin:1em 0;
}
col{
border-right: 1px solid black;
}
#albumCol{
border:none;
}
thead {
background: #ccc;
border-top: 1px soild #a5a5a5;
border-bottom:1px soild #a5a5a5;
}
th{
font-weight:normal;
text-align:left;
}
th, td{
padding: 0.1em 1em;
}
#playlistPosHead{
text-indent:-1000em;
}
tbody tr:nth-child(even){
background-color:#edf5ff;
}
tr:hover{
background-color:#3d80df;
color:#fff;
}
thead tr:hover{
background-color:transparent;
color:inherit;
}
??首先葫督,給表格設(shè)置一個寬度,調(diào)整表格間距并使每個方格的數(shù)據(jù)左對齊板惑,
使用:nth-child選擇器交錯使偶數(shù)行或者奇數(shù)行顯示不同顏色橄镜,不需要使用給每個交替行添加類。:hover動態(tài)偽類可以在鼠標滑動到某一行時顯示冯乘,某個樣式洽胶。當然還可以給表格加上邊框,或者將字體加粗也是同樣的方法裆馒。
表單
<fieldset>
<legend>個人信息</legend>
<p>
<label for="Place Of Birth">Place Of Birth:</label>
<select name="Place Of Birth">
<option value="1">China</option>
<option value="2">USA</option>
</select>
</p>
<p>
<label for="Date Of Birth">Date Of Birth:</label>
<input type="text" name="DateOfBirth" id="DateOfBirth"/>
<select name="monthOfBirth" id="monthOfBirth">
<option value="1">January</option>
<option value="2">Februry</option>
<option value="3">March</opyion>
</select>
<input type="text" name="YearOfBirth" id="YearOfBirth" />
</p>
<h4>Favorite Color:</h4>
<legend>
<p>
<input type="checkbox" name="red" id="red" value="red" />
<label>red</label>
<input type="checkbox" name="bule" id="bule" value="bule" />
<label>bule</label>
<input type="checkbox" name="black" id="black" value="black" />
<label>black</label>
</p>
</legend>
<legend>
<input type="checkbox" name="yellow" id="yellow" value="yellow" />
<label>yellow</label>
<input type="checkbox" name="orange" id="orange" value="orange" />
<label>orange</label>
<input type="checkbox" name="white" id="white" value="white" />
<label>white</label>
</legend>
</fieldset>
<input type="button" name="submit" id="submit" value="submit" />
??先通過html的標簽和屬性創(chuàng)建一個簡單的表單姊氓,<legend>標簽可以對整個組進行定位。在這個表單上用到的所有表單控件都包含name和id屬性领追,在表單輸入控件和標簽之間創(chuàng)建關(guān)聯(lián)需要id屬性他膳,而將表單數(shù)據(jù)發(fā)送回服務(wù)器需要name屬性。
fieldset{
width:30em;
}
input#DateOfBirth{
width:50px;
margin-right: 0.5em;
}
select#monthOfBirth{
width: 10em;
margin-right: 0.5em;
}
input#YearOfBirth{
width:50px;
}
??同樣可以給表單設(shè)置任意寬度绒窑,不讓隨瀏覽器變化棕孙,當需要某種形式的反饋消息,可以在適當?shù)膮^(qū)域添加一個錯誤消息提示◇翱。可以將反饋文本放在<span>標簽中钦铺,并放在源代碼中文本輸入元素的后面,然后使用CSS進行定位肢预。
??在之前模仿寫趣醫(yī)網(wǎng)的靜態(tài)頁面時矛洞,用了大量的div標簽,雖然可以達到自己想要的效果烫映,但使得代碼看起來比較亂又難讀懂沼本,在后面寫的過程中應(yīng)多熟練使用一些有意義的標簽元素。