HTML+CSS导航栏⾃适应⽅案css⽂件
#header{
background-color: #333;
padding: 10px 10%;
}
/* 导航栏按钮 */
.btn{
display: none;
float:right;
margin-top: 5px;
border: 0;
border-radius: 5px;
width: 40px;
height: 40px;
}
/* ⽂字Logo */
#header a.logo{
float:left;
font-weight: bold;
font-size: 39px;
line-height: 50px;
}
#header div.nav{
height: 50px;
}
#header ul.nav-bar{
list-style: none;
float: right;
line-height: 50px;
}
#header ul.nav-bar li{
float:left;
padding: 0 10px;
}
@media screen and (max-width: 768px){
#header{
padding: 10px 5%;
height: 50px;
overflow: hidden;
}
#header a.logo{
line-height: 55px;
font-size: 30px;
}
.
btn{
display: block;
}
#header ul.nav-bar{
margin-top: 15px;
border-top: solid 1px #111;
width:100%;
}
#header ul.nav-bar li{
float: none;
padding: 0 10px;
}
}
}
#container{
width: 100%;
height: 300px;
background:#FFBBBB;
}
html⽂件
<!DOCTYPE html>
<html>js导航栏下拉菜单
<head>
<meta charset="utf-8"/>
<meta name="viewport"content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no"/> <title></title>
<link rel="stylesheet"type="text/css"href="./style.css">
<script src="apps.bdimg/libs/jquery/2.1.4/jquery.min.js"></script>
</head>
<body>
<div id="header">
<div class="nav">
<a href="#"class="logo">⾃适应导航栏</a>
<div id="nav-btn"class="btn">
<img src="./menu.png" />
</div>
<ul class="nav-bar">
<li><a href="#">⾸页</a></li>
<li><a href="#">归档</a></li>
<li><a href="#">标签</a></li>
<li><a href="#">关于</a></li>
</ul>
</div>
</div>
<div id="container">
<h3>正⽂内容Content</h3>
</div>
</body>
<script type="text/javascript">
// 开关状态
var open =false;
$('#nav-btn').click(function(){
// 按钮状态
$(this).css("background-color", open ?'#333':'#222');
var navBar =$('.nav-bar');
// 设置header的⾼度,将导航列表显⽰出来
var height = navBar.offset().top + navBar.height();
$('#header').animate({
height: open ?50: height
});
// 修改开关状态
open =!open;
});
</script>
</html>
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论