CSS中的隔行换色

来源:互联网 发布:淘宝裂变软件多少钱 编辑:程序博客网 时间:2024/06/07 05:35
一.表格的<tr>隔行换色
 <style type="text/css">
<!--
tr {background-color:expression((this.sectionRowIndex==0)?"":
(this.sectionRowIndex%2==0)?"red":"blue")}
-->
</style>
</HEAD>
<table>
<tr>
<td>第1行</td><td>第1行</td>
</tr>
<tr>
<td>第2行</td><td>第2行</td>
</tr>
<tr>
<td>第3行</td><td>第3行</td>
</tr>
<tr>
<td>第4行</td><td>第4行</td>
</tr>
<tr>
<td>第5行</td><td>第5行</td>
</tr>
</table>
二.表格的td换色
 <style type="text/css">
<!--
tr {background-color:expression((this.sectionRowIndex%2==0)?"red":"blue")}
td {background-color:expression((this.cellIndex%2==0)?"":((this.parentElement.sectionRowIndex%2==0)?"green":"yellow"))}
-->
</style>
</HEAD>
<table>
< tr><td>第1行</td><td>第1行</td><td>第1行< /td><td>第1行</td><td>第1行</td></tr>
< tr><td>第2行</td><td>第2行</td><td>第2行< /td><td>第2行</td><td>第2行</td></tr>
< tr><td>第3行</td><td>第3行</td><td>第3行< /td><td>第3行</td><td>第3行</td></tr>
< tr><td>第4行</td><td>第4行</td><td>第4行< /td><td>第4行</td><td>第4行</td></tr>
< tr><td>第5行</td><td>第5行</td><td>第5行< /td><td>第5行</td><td>第5行</td></tr>
</table>
三.Li标签隔行换色代码
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style>
.t1 {background-color:#336699;text-align:center}
.t2 {background-color:#ffcc00;text-align:center}
ul{list-style:none;width:200px;}
ul li{height:20px;line-height:20px;width:200px;}
</style>
<script>
<!-- POPOEVER is drinking half bottle of lemon tea:) --
function ulLi() {
for (i=1;i<bkg1.children.length+1;i++) {
(i%2>0)?(bkg1.children(i-1).className = "t1"):(bkg1.children(i-1).className = "t2");
}
}
//-- Lemon tea is bottom up -->
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000" onLoad="ulLi();">
<ul id="bkg1">
<li>li背景变变变</li>
<li>li背景变变变</li>
<li>li背景变变变</li>
<li>li背景变变变</li>
<li>li背景变变变</li>
<li>li背景变变变</li>
<li>li背景变变变</li>
<li>li背景变变变</li>
</ul>
</body>
</html>

出自: http://www.blogjava.net/liuwentao253/archive/2007/08/07/134903.html