用css循环如何做一个表格,要求奇偶行颜色不一致 5

 我来答
山水阿锐
2015-06-21 · TA获得超过34.3万个赞
知道顶级答主
回答量:23.7万
采纳率:91%
帮助的人:3.1亿
展开全部
<!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=utf-8" />
<link href="table.css" type="text/css" rel="stylesheet" />
<title>table test</title>
<!-- <style>
table tbody tr:hover{
background-color: #EEECEB;
}
</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>
/*
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;
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式