辛星与您使用CSS导航条

第一步。我们创建了一个新的my.html档。在内容填入如下面。这个html文件不动,直到最后。正是这些内容:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <link rel="stylesheet" type="text/css" href="xin.css">
</head>
<body>
<div class = "nav">
<ul>
    <li><a href="#">辛星PHP</a></li>
    <li><a href="#">辛星Python</a></li>
    <li><a href="#">辛星CSS</a></li>
    <li><a href="#">辛星HTML</a></li>
    <li><a href="#">辛星jQuery</a></li>
    <li><a href="#">辛星Java</a></li>

</ul></div>
</body>
</html>
第二步,我们開始新建一个xin.css文件,然后開始进行调整这些导航条的显示格式。我们要做的第一步就是先把列表的小圆点给去掉。我们先写例如以下代码:

.nav ul{list-style-type: none;}
我们发现小圆点没了。可是。如今这些列表元素都是竖向排列的,我们想让它们横向排列。

第三步,我们通过设置li的浮动来让它们横向排列,我们在第二行加入代码,因此整个代码成为:

.nav ul{list-style-type: none;}
.nav li{float:left;}
第四步,我们发现如今它们是到了一起了,可是是连在一起的,这是为什么呢,由于它们没有设置宽度,我们仅仅要给他们设置了一定的宽度。它们就会分开啦,可是我们同一时候还能够设置一下背景色,因此该代码就成为了例如以下代码:

.nav ul{list-style-type: none;}
.nav li{float:left;width: 100px;background:#CCC;}

第五步我们就開始设置鼠标的样式了,顺便我们把下划线给去掉。我们前面介绍过伪类的概念,假设读者不熟悉。也能够到前面翻翻我的教程。我们同一时候加入背景颜色什么的,因此它的代码成为以下这个样子:

.nav ul{list-style-type: none;}
.nav li{float:left;width: 100px;background:#CCC;}
.nav a:link{color:#666;background: #CCC;text-decoration: none;}
.nav a:visited{color: #666;text-decoration: none;}
.nav a:hover{color: #FFF;font-weight: bold;text-decoration: underline;background: #0F0;}
第六步也是源自我们的问题,我们调整一下大小,即我们设置一下.nav a的属性值,代码例如以下:

.nav ul{list-style-type: none;}
.nav li{float:left;width: 100px;}
.nav a:link{color:#666;background: #CCC;text-decoration: none;}
.nav a:visited{color: #666;text-decoration: none;}
.nav a:hover{color: #FFF;font-weight: bold;text-decoration: underline;background: #0F0;}
.nav a{display: block;text-align: center;height: 30px;font-weight: bold;}
第七步就是我们的这个导航条是黏在一起的,我们须要分开菜看上去更加舒服一点,因此我们这里设置一下li的属性。让它的边距设置为3px,然后在让字体的大小适合该导航条的大小。最后的代码例如以下:

.nav ul{list-style-type: none;}
.nav li{float:left;width: 100px;margin-left: 3px;line-height: 30px;}
.nav a:link{color:#666;background: #CCC;text-decoration: none;}
.nav a:visited{color: #666;text-decoration: none;}
.nav a:hover{color: #FFF;font-weight: bold;text-decoration: underline;background: #0F0;}
.nav a{display: block;text-align: center;height: 30px;font-weight: bold;}


到如今为止。我们的导航条就做完了,假设读者是一位高手,可能会指出它的不足,可是毕竟是用手写的,没用不论什么的图片,让我们来看一下总体效果把:








版权声明:本文博主原创文章,博客,未经同意不得转载。

posted @ 2015-10-25 10:30  blfshiye  阅读(145)  评论(0编辑  收藏  举报