温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何实现当鼠标经过表格数据行时颜色不同且奇偶行颜色也不同

发布时间:2021-09-30 13:57:19 来源:亿速云 阅读:134 作者:iii 栏目:web开发

这篇文章主要介绍“如何实现当鼠标经过表格数据行时颜色不同且奇偶行颜色也不同”,在日常操作中,相信很多人在如何实现当鼠标经过表格数据行时颜色不同且奇偶行颜色也不同问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”如何实现当鼠标经过表格数据行时颜色不同且奇偶行颜色也不同”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

代码如下:

<!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;
}

到此,关于“如何实现当鼠标经过表格数据行时颜色不同且奇偶行颜色也不同”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

css
AI