首页 > 开发 > CSS > 正文

CSS2实现的隔行换色

2020-10-23 18:40:46
字体:
来源:转载
供稿:网友
利用了CSS2 的 相邻选择符 IE7以下不支持

隔行换色示例:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>放弃class与js实现隔行换色效果</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Author" content="PengRong" />

<style type="text/css">
<!-- /* PR-CSS */
table {border-collapse:collapse;border:solid #999;border-width:1px 0 0 1px;}
table td {border:solid #999;border-width:0 1px 1px 0;}

tr {background:#eee;}
tr + tr {background:#ccc;}
tr + tr + tr {background:#eee;}
tr + tr + tr + tr {background:#ccc;} 
tr + tr + tr + tr + tr {background:#eee;} 
-->
</style>
</head>

<body>
<table>
<tr>
<td>12</td><td>12</td><td>12</td><td>12</td>
</tr>
<tr>
<td>12</td><td>12</td><td>12</td><td>12</td>
</tr>
<tr>
<td>12</td><td>12</td><td>12</td><td>12</td>
</tr>
<tr>
<td>12</td><td>12</td><td>12</td><td>12</td>
</tr>
<tr>
<td>12</td><td>12</td><td>12</td><td>12</td>
</tr>
</table>
</body>
</html>




隔列换色示例: 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>放弃class与js实现隔列换色效果</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Author" content="PengRong" />

<style type="text/css">
<!-- /* PR-CSS */
table {border-collapse:collapse;border:solid #999;border-width:1px 0 0 1px;}
table td {border:solid #999;border-width:0 1px 1px 0;}

td {background:#eee;}
td + td {background:#ccc;}
td + td + td {background:#eee;}
td + td + td + td {background:#ccc;} 
td + td + td + td + td {background:#eee;} 
-->
</style>
</head>

<body>
<table>
<tr>
<td>12</td><td>12</td><td>12</td><td>12</td>
</tr>
<tr>
<td>12</td><td>12</td><td>12</td><td>12</td>
</tr>
<tr>
<td>12</td><td>12</td><td>12</td><td>12</td>
</tr>
<tr>
<td>12</td><td>12</td><td>12</td><td>12</td>
</tr>
<tr>
<td>12</td><td>12</td><td>12</td><td>12</td>
</tr>
</table>
</body>
</html>
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表