css中设置html的外部样式表的奇偶行交替色类似

html-css011

css中设置html的外部样式表的奇偶行交替色类似,第1张

可以啊,用css3或者jq实现。

可以使用css3的奇偶选择器,如:

tr:nth-child(odd){background-color:#FFE4C4}

tr:nth-child(even){background-color:#F0F0F0}

li:nth-child(odd)是设置奇数行的背景色,li:nth-child(even)是设置偶数行的。但是css3不兼容IE9以下的浏览器,如果需要考虑到兼容问题的话,可以使用jq设置,如:

$("table  tr:nth-child(even)").css("background-color","#FFE4C4")    //设置偶数行的背景色

$("table  tr:nth-child(odd)").css("background-color","#F0F0F0")    //设置奇数行的背景色

步骤如下:ul li:nth-child(2n);ul li:nth-child(2n+1)

CSS部分:

.list {width:500pxmargin:0 auto}

.list ul {background:url(http://www.bluebirdsky.cn/images/upfiles/row_bg.gif)}

.list li {height:25pxline-height:25pxtext-align:leftpadding-left:10px}

Demo演示

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/htmlcharset=gb2312" />

<meta name="Author" content="青鸟" />

<meat name="Author BlogURL" content="http://www.bluebirdsky.cn/[Bluebirdsky]"

步骤如下:ul li:nth-child(2n);ul li:nth-child(2n+1)

CSS部分:

.list {width:500pxmargin:0 auto}

.list ul {background:url(http://www.bluebirdsky.cn/images/upfiles/row_bg.gif)}

.list li {height:25pxline-height:25pxtext-align:leftpadding-left:10px}

Demo演示

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/htmlcharset=gb2312" />

<meta name="Author" content="青鸟" />

<meat name="Author BlogURL" content="http://www.bluebirdsky.cn/[Bluebirdsky]"