HTML5如何制作特效导航栏?

html-css012

HTML5如何制作特效导航栏?,第1张

鼠标移上去时,改变li元素的大小、背景色、文字颜色等

代码如下:

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title></title>

<style type="text/css">

ul {

margin: 0

padding: 0

}

ul li {

list-style: none

width: 130px

height: 50px

text-align: center

line-height: 50px

font-size: 20px

position: relative

margin-left: 10px

}

div {

width: 150px

height: 500px

border: 1px dashed #000000

text-align: center

}

.active {

background-color: green

color: #fff

}

.show {

width: 2px

height: 20px

position: absolute

left: 10px

top: 15px

background-color: white

}

.li1 {

left: 20px

border-radius: 5px

}

</style>

</head>

<body>

<div id="div1">

<ul>

<li><span></span>雅望天堂1</li>

<li><span></span>雅望天堂2</li>

<li><span></span>雅望天堂3</li>

<li><span></span>雅望天堂4</li>

</ul>

</div>

<script type="text/javascript">

var oLi = document.getElementsByTagName("li")

var oSpan = document.getElementsByTagName("span")

for (var i = 0i <oLi.lengthi++) {

oLi[i].onmouseover = function() {

var sp = this.childNodes[0]

console.log(sp)

for (var i = 0i <oLi.lengthi++) {

oLi[i].setAttribute("class", "")

oSpan[i].setAttribute("class", "")

}

this.setAttribute("class", "active li1")

sp.setAttribute("class", "show")

}

oLi[i].onmouseout = function() {

for (var i = 0i <oLi.lengthi++) {

oLi[i].setAttribute("class", "")

}

}

}

</script>

</body>

</html>

这应该是你要的效果

html做导航栏步骤如下:

1、用Dreamweaver新建一个HTML文件;

2、按ctrl+s先保存,以防突然断电数据丢失;

3、修改title为html+css实现横向导航;

4、新建一个divid为“a”,添加ulli标签;

5、在li中添加自己想要的文字并调整好文字间距,按F12预览;6、首先去掉字体前面的小黑点。

HTML的全称为超文本标记语言,是一种标记语言。它包括一系列标签,通过这些标签可以将网络上的文档格式统一,使分散的Internet资源连接为一个逻辑整体。