1. 程式人生 > >當鼠標經過表格數據行時顏色不同且奇偶行顏色也不同 (純CSS)

當鼠標經過表格數據行時顏色不同且奇偶行顏色也不同 (純CSS)

creat bsp auth lin itl 出錯 -type 姓名 class

技術分享

<!DOCTYPE html> 
<!-- 
To change this license header, choose License Headers in Project Properties. 
To change this template file, choose Tools | Templates 
and open the template in the editor. 
--> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 

<title>table test</title> 
 <style> 
 
/* 
To change this license header, choose License Headers in Project Properties. 
To change this template file, choose Tools | Templates 
and open the template in the editor. 
*/ 
/* 
Created on : 2014-7-9, 14:24:31 
Author : Administrator 
*/ 
body{ margin:0 auto; text-align:center} 
/*設置表頭的margin為0則表居中顯示,border為0則無邊界*/ 
table{margin:0 auto; 
border:0px; 
solid:#000 
} 
/*設置th表頭的屬性,font-weight為bold則顯示為黑粗*/ 
table tr th{ height:28px; 
width: auto; 
line-height:28px; 
background:#999; 
font-weight:bold 
} 
table tbody tr{ 
height:28px; 
line-height:28px; 
text-align:center; 
background:#FFF; 
vertical-align:middle; 
} 
/* 
*設置鼠標經過顏色的變化 
*/ 
/*采用csss的這個方法,獲得奇數行,讓後設置其屬性,這樣避免使用expression這個容易出錯的方法*/ 
table tbody tr:nth-child(odd){ 
background-color: #DEDEDE 
} 

table tbody tr:hover{ 
background-color: #CCCCCC; 
} 
</style> 
</head> 
<body> 
<table> 
<tr> 
<th>姓名</th> 
<th>性別</th> 
<th>班級</th> 
</tr> 
<tbody> 
<tr> 
<td>姓名</td> 
<td>男</td> 
<td>計算機科學與技術一班</td> 
</tr> 
<tr> 
<td>段萌</td> 
<td>男</td> 
<td>軟工一班</td> 
</tr> 
<tr> 
<td>段萌</td> 
<td>男</td> 
<td>軟工一班</td> 
</tr> 
<tr> 
<td>段萌</td> 
<td>男</td> 
<td>軟工一班</td> 
</tr> 
<tr> 
<td>段萌</td> 
<td>男</td> 
<td>軟工一班</td> 
</tr> 
</tbody> 
</table> 
</body> 
</html>

  

當鼠標經過表格數據行時顏色不同且奇偶行顏色也不同 (純CSS)