使用CSS设置表格隔行变色

html-css0302

使用CSS设置表格隔行变色,第1张

在CSS中可使用:nth-child()选择器来实现表格隔行变色效果。:nth-child()选择器用于根据元素在一组兄弟中的位置来匹配元素;它匹配第n个子元素。语法:其中arg是表示匹配元素的模式的参数;它可以是一个数字(number)、一个关键字(odd 或 even)或一个函数式。想要隔行设置表格的行颜色需要使用到关键字(odd 或 even),下面就来介绍一下: ●  odd :表示位置为奇数的元素,即1,3,5等。 ●  even: 表示位置为偶数的元素,即2,4,6等。示例1: 为在表中交替的偶数行设置颜色 效果图:示例2: 为在表中交替的奇数行设置颜色 效果图: 更多 web开发 知识,请查阅 HTML中文网 !!

如下几点建议:

1)DIV+CSS是用来替换表格排版的,表格还是用table。

2)可以尝试用ul li 做简单的表格

3)用DIV+CSS做表格的方法和做页面布局的方法一致,所以你要学习一下这方面,可以参考一下相关视频教程。如果做复杂的表格因为需要反复嵌套效果就不好了。

<style type="text/css">

.div1{border:1px solid #dededewidth:600pxheight:200pxmargin:0px auto}

.left{width:299pxheight:100%border-right:1px solid #dededefloat:leftdisplay:inline}

.left{width:300pxheight:100%float:leftdisplay:inline}

.left1{width:100%height:100pxfloat:leftdisplay:inlinemargin-top:10px}

.left1 img{margin-left:10px}

.left1 p{margin:0pxpadding:0px}

.left1 img,.left1 div{float:leftdisplay:inline}

</style>

<div class="div1">

<div class="left">

<div class="left1"><img src="" width="75px" height="75px" /><div><p>aaaaaaaa</p><p>谁谁谁</p></div></div>

<div class="left1"><img src="" width="75px" height="75px" /><div><p>aaaaaaaa</p><p>谁谁谁</p></div></div>

</div>

<div class="right">

<h1>654564646</h1>

</div>

</div>

剩下的自己再调调吧