Home  >  Article  >  Web Front-end  >  CSS实现的鼠标经过链接切换背景图片实例代码_html/css_WEB-ITnose

CSS实现的鼠标经过链接切换背景图片实例代码_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-24 11:31:151922browse

CSS实现的鼠标经过链接切换背景图片实例代码:
很多导航栏都有这样的效果,当鼠标滑过的时候能够实现背景图片的切换,算是一个比较好的效果吧,也算是对导航栏最基本的美化了。
代码实例如下:

<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta name="author" content="http://www.softwhy.com/" /><title>蚂蚁部落</title><style type="text/css">ul li{  list-style:none;  width:150px;  height:30px;  line-height:30px;  text-align:center;  float:left;  margin-left:5px;}ul li a{  display:block;  width:150px;  height:30px;  text-decoration:none;  background:blue;}ul li a:hover{background:red}</style></head><body>  <ul>    <li><a href="#">蚂蚁部落一</a></li>    <li><a href="#">蚂蚁部落二</a></li>    <li><a href="#">蚂蚁部落三</a></li>    <li><a href="#">蚂蚁部落四</a></li>  </ul></body></html>

以上代码中,为了便于演示,背景图片用背景色替代了,在实际应用中只要把背景色替换为背景颜色就可以了。
原理非常的简单,主要是用到了链接伪类,具体可以参阅CSS的伪类选择符E:hover一章节。

原文地址是:http://www.softwhy.com/forum.php?mod=viewthread&tid=9798

更多内容可以参阅:http://www.softwhy.com/divcss/

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn