CSS实现类似导航翻转功能例子

 

 

今天写了一个css实现类化导航翻转功能例子,想拿出来和大家分享一下;

首先看看它的效果:

鼠标移上去的时候:

背景和字体的颜色都变了,效果如下

 

 

首先写一个HTML文档,内容如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>导航翻转功</title>

<link href="test2.css" rel="stylesheet" type="text/css" />

</head>

 

<body>

      <ul>

        <li id="blogger"><a href="www.baidu.com" ><strong>my</strong> blogger</a></li>

        <li id="google"><a href="www.google.com"><strong>my</strong> google</a></li>

        <li id="sogou"><a href="www.sogou.com"><strong>my</strong> sogou</a></li>

 <li id="cto"><a href="www.51cto.com"><strong>my</strong> 51cto</a></li>

</ul>

/*id属性的名称的命名规则,是不能数字开头。*/

</body>

</html>

下面来开始写CSS代码:

1.       去掉无序列表前面的加点默认圆点和内外边距。

ul{

list-style:none;

margin:0;

padding:0;

}

2.       li中使用float:left使得li水平排列。

}

ul li{

float:left;

margin:0;

padding:0;

}

3.       设置lia标记的链接字体样式,并设置display:block;同时去年下划线。

ul li a{

color:#77;

display:block;

padding:90px 10px 5px;

text-align:center;

text-decoration:none;

}

4.       a标记添加背景图片。

ul li#blogger a{

background:url(face01.png) transparent no-repeat top center;

}

ul li#google a{

background:url(face02.png) transparent no-repeat top center;;

}

ul li#sogou a{

background:url(face03.png) transparent no-repeat top center;

}

ul li#cto a{

background:url(face04.png) transparent no-repeat top center;

}

5.       设置鼠标经过时,链接字体的颜色。

ul li#blogger a:hover,

ul li#google a:hover,

ul li#sogou a:hover,

ul li#cto a:hover{

background-color:#FCC;

color:#000;

}

Ok,完成,测试一下效果。

源代码见附件: