HTML5如何才能让导航栏固定顶部不动,且!且!且!不遮挡住下面的DIV???

html-css015

HTML5如何才能让导航栏固定顶部不动,且!且!且!不遮挡住下面的DIV???,第1张

HTML5让导航栏固定顶部不动且不遮挡住下面的DIV方法如下:

1,首先在html中,添加良好的导航内容。

2,后者是网页的具体内容,这里的代码比较简单。

3,在样式中,首先在菜单中定义一些样式。

4,此时,在运行页面时,滚动条滚动后导航将消失。

5,为了将导航栏固定在顶部,可以添加样式位置:固定;最高:0在导航容器中,键是第一个样式,因此其位置是固定的。

6,此时,页面开始运行,页面向上滚动,并且导航始终在顶部。

鼠标移上去时,改变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>

这应该是你要的效果