CSS实现把鼠标放在行上整行变色 
		
			
			发表于:2015-07-21 14:50:08
			 |
			阅读数:--次 |
			作者:html,css 
		
		
			 
			
		
		
			摘要: CSS如何实现把鼠标放在行上整行变色:在很多网站都有这样的效果,那就是当鼠标放在一个文章列表行的时候,此行就会显示与其他行不同的颜色,本站的文章列表也具有这样的效果,便于浏览者识别,非常人性化,下面就简单介绍一下如何实现此效果。代码实例如下:蚂蚁部落 html div+css javascri...
		
		
			CSS如何实现把鼠标放在行上整行变色: 在很多网站都有这样的效果,那就是当鼠标放在一个文章列表行的时候,此行就会显示与其他行不同的颜色,本站的文章列表也具有这样的效果,便于浏览者识别,非常人性化,下面就简单介绍一下如何实现此效果。代码实例如下: 
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.webkfa.com/" />
<title>学到老web开发</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> 
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.webkfa.com/" />
<title>学到老web开发</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.webkfa.cn/" />
<title>学到老web开发</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> 
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.webkfa.cn/" />
<title>学到老web开发</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>