HTML+CSSナビゲーションバー適応方式
cssファイル
htmlファイル
#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ファイル
<html>
<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="https://apps.bdimg.com/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" style="margin: 5px;width: 30px;height:30px;" />
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> Contenth3>
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>