码迷,mamicode.com
首页 > 其他好文 > 详细

SS如何实现把鼠标放在行上整行变色

时间:2015-07-21 14:26:57      阅读:98      评论:0      收藏:0      [点我收藏+]

标签:

CSS如何实现把鼠标放在行上整行变色:

在很多网站都有这样的效果,那就是当鼠标放在一个文章列表行的时候,此行就会显示与其他行不同的颜色,本站的文章列表也具有这样的效果,便于浏览者识别,非常人性化,下面就简单介绍一下如何实现此效果。代码实例如下:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.51texiao.cn/" />
<title>蚂蚁部落</title>
<style type="text/css">
a{text-decoration:none;}
li:hover{background-color:green;}
</style>
</head>
<body>
<ul>
  <li><a href="#">html</a></li>
  <li><a href="#">div+css</a></li>
  <li><a href="#">javascript</a></li>
  <li><a href="#">Jquery</a></li>
</ul>
</body>
</html>

以上代码通过使用E:hover伪类选择器实现了此效果。

但是此中方法有个缺点,就是IE6浏览器不支持除去a元素之外的E:hover伪类选择器。下面介绍一下能够兼容所有浏览器的方法,代码实例如下:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.51texiao.cn/" />
<title>蚂蚁部落</title>
<style type="text/css">
a{text-decoration:none;}
.over{background-color:green;}
.out{background-color:#FFF;}
</style>
</head>
<body>
<ul>
  <li onmouseover="this.className=‘over‘" onmouseout="this.className=‘out‘">
    <a href="#">html</a>
  </li>
  <li onmouseover="this.className=‘over‘" onmouseout="this.className=‘out‘">
    <a href="#">div+css</a>
  </li>
  <li onmouseover="this.className=‘over‘" onmouseout="this.className=‘out‘">
    <a href="#">javascript</a>
  </li>
  <li onmouseover="this.className=‘over‘" onmouseout="this.className=‘out‘">
    <a href="#">Jquery</a>
  </li>
</ul>
</body>
</html>

原文地址是:http://www.51texiao.cn/div_cssjiaocheng/2015/0504/723.html

最原始地址是:http://www.softwhy.com/forum.php?mod=viewthread&tid=4643

SS如何实现把鼠标放在行上整行变色

标签:

原文地址:http://www.cnblogs.com/softwhy/p/4664111.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!