整合营销服务商

电脑端+手机端+微信端=数据同步管理

免费咨询热线:

HTML+CSS做二级导航




lt;!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>导航菜单</title>

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

</head>

<body>

<!--头部-->

<header>

<div class="container">

<!--导航条-->

<ul class="nav">

<li style="background-color: gold;">

<a href="#">首页</a>

</li>

<li>

<a href="#">公司概况</a>

<ul class="nav-list">

<li>公司简介</li>

<li>发展历程</li>

<li>组织机构</li>

<li>总经理寄语</li>

</ul>

</li>

<li>

<a href="#">公司文化</a>

<ul class="nav-list">

<li>文化理念</li>

<li>员工活动</li>

<li>党/工/团建设</li>

</ul>

</li>

<li>

<a href="#">公司新闻</a>

</li>

<li>

<a href="#">服务内容</a>

</li>

<li>

<a href="#">法律政策</a>

</li>

<li>

<a href="#">人才招聘</a>

</li>

<li>

<a href="#">联系我们</a>

</li>

</ul>

</div>

</header>

</body>

</html>

nav.css

@charset "utf-8";

*{

margin: 0px;

padding: 0px;

}

CSS

#goTopBtn, #goBottom, #shangy, #xiay, #menuPage, #lPage, #fPage{

width: 18px;

line-height: 1.2;

padding: 5px 0;

font-size: 12px;

text-align: center;

position: fixed;

right: 10px;

cursor: pointer;

filter: Alpha(opacity=30);

opacity=.3;

font-weight:bold;

}

#goTopBtn, #goBottom, #menuPage, #lPage, #fPage{

background-color:#999;

color:#000;

}

#shangy, #xiay, #lPage, #fPage{

background-color: #bbb;

color: #000;

}

#fPage{

bottom: 236px;

height:42px;

white-space:nowrap;

overflow:hidden;

//writing-mode:tb-rl;

}

#menuPage{

bottom: 198px;

height:27px;

white-space:nowrap;

overflow:hidden;

}

#lPage{

bottom: 145px;

height:42px;

white-space:nowrap;

overflow:hidden;

}

#goTopBtn{

bottom: 105px;

}

#goBottom {

bottom: 30px;

}

#shangy {

bottom: 80px;

}

#xiay {

bottom: 55px;

}

#goTopBtn:hover, #goBottom:hover, #shangy:hover, #xiay:hover, #menuPage:hover, #lPage:hover, #fPage:hover{

background-color:#ccc;

border:#ccc 0px solid;

}

#goTopBtn a:link, #goBottom a:link, #xiay a:link, #shangy a:link, #menuPage a:link, #menuPage a:visited, #lPage a:link, #fPage a:link, #lPage a:visited, #fPage a:visited {

text-decoration: none;

color:white;

}

2 HTML

<div id="fPage"><a id="fPagea" href="javascript:void(null)" target="_self">上<br />一<br />页</a></div>

<div id="menuPage"><a href="index.html" target="_self">目<br />录</a></div>

<div id="lPage"><a id="LPagea" href="javascript:void(null)" target="_self">下<br />一<br />页</a></div>

<div style="display:none" id="goTopBtn"><a target="_self" style="color:#fff;">&and;</a></div>

<div style="display:none" id="shangy">

<a onclick="shangy()" target="_self" style="color:#fff;">&uarr;</a></div>

<div id="xiay">

<a onclick="xiay()" target="_self" style="color:#fff;">&darr;</a></div>

<div id="goBottom">

<a onclick="downn()" target="_self" style="color:#fff;">&or;</a></div>

3 JS

<script type=text/javascript>

goTopEx();

function xiay(){

window.scrollBy(0,window.innerHeight-10);

}

function shangy(){

window.scrollBy(0,-window.innerHeight+10);

}

var obj3=document.getElementById("xiay");

var obj4=document.getElementById("goBottom");

function getHeight(){

if(browser4=="ch"){

//谷歌浏览器

return document.body.clientHeight;

}else{

//IE、firefox等浏览器

return document.documentElement.clientHeight;

}

}

getHeight()<window.innerHeight+50?obj3.style.display="none":obj3.style.display="";

getHeight()<window.innerHeight+50?obj4.style.display="none":obj4.style.display="";

if(browser4!="ch"){//firefox需要尝一下才显示向下图标

xiay();

shangy();

}

//上一页、下一页按钮,需要文件名是数字

var strUrl=window.location.href;

var arrUrl=strUrl.split("/");

var thispage=arrUrl[arrUrl.length-1];

var thispage2=thispage.split(".");

var thispage3=thispage2[thispage2.length-2];

if(thispage3 == 1){

var obj5=document.getElementById("fPage");

obj5.style.display="none"

}else{

var fpage = thispage3 - 1;

fpage = fpage +".html"

document.getElementById("fPagea").href=fpage;

}

if(thispage3 == 100){

var obj6=document.getElementById("lPage");

obj6.style.display="none"

}else{

var fpage = thispage3 - 1;

fpage = fpage +".html"

document.getElementById("fPagea").href=fpage;

}

</script>

当将鼠标停留在“上一面”按钮处时,网页效果如下:

-End-

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>HTML+CSS 二级导航</title>
<style type="text/css">
*{
    margin: 0;
    padding: 0;
}
ul,ol{
    list-style: none;
}
a{
    color: #000;
    display: block;
    width: 140px;
    height: 40px;
    text-align: center;
    line-height: 40px;
    text-decoration: none;
}
/* ******************************************* */
.nav{
    width: 100%;
    height: 40px;
    background-color: skyblue;
}
.nav>ul{
    width: 1200px;
    height: 40px;
    margin: 0 auto;
    /* 这个背景色是方便大家伙看的 */
    /* background-color: red; */
}
.nav>ul>li{
    float: left;
    width: 140px;
    height: 40px;
    /*让ol(二级导航根据他进行定位 所以li进行相对定位)*/
    position: relative;
}
.nav>ul>li>ol{
    background-color: skyblue;
    position: absolute;
    left: 0;
    top: 40px;
    display: none;/*初始值隐藏*/
}
/* 悬浮的效果 */
a:hover{
    color: #fff;
    background-color: deepskyblue;
}
.nav>ul>li:hover>a{
    color: #fff;
    background-color: deepskyblue;
}
.nav>ul>li:hover>ol{
    display: block;
}
</style>
</head>
<body>
<div class="nav">
<ul>
<li><a href="">首页</a></li>
<li>
<a href="">法师</a>
<ol>
<li><a href="">妲己</a></li>
<li><a href="">甄姬</a></li>
<li><a href="">安琪拉</a></li>
<li><a href="">张良</a></li>
</ol>
</li>
<li><a href="">战士</a></li>
<li>
<a href="">刺客</a>
<ol>
<li><a href="">荆轲</a></li>
<li><a href="">张飞</a></li>
<li><a href="">关羽</a></li>
<li><a href="">黄忠</a></li>
<li><a href="">马超</a></li>
<li><a href="">赵云</a></li>
<li><a href="">许诸</a></li>
</ol>
</li>
<li><a href="">射手</a></li>
<li><a href="">坦克</a></li>
<li>
<a href="">辅助</a>
<ol>
<li><a href="">蔡文姬</a></li>
<li><a href="">鬼谷子</a></li>
<li><a href="">庄周</a></li>
</ol>
</li>
</ul>
</div>
<p>HTML+CSS 二级导航</p>
</body>
</html>