我正在努力使这个菜单响应,特别是我希望它看起来像这样:☰ - >当我点击它时显示链接。
(蓝色按钮,我也希望它显示为普通链接,就像其他链接一样)
我不想使用Bootstrap,我想使用JavaScript和CSS。
HTML代码:
<html>
<head>
<link rel="stylesheet" type="text/css" href="./css/style.css" />
</head>
<body>
<div class="navigation-main">
<div id="wrapper">
<div class="logo">
<img src="./img/logo-main.png" />
</div>
<div id="menu">
<a href="#" />Home</a>
<a href="#" />Home</a>
<a href="#" />Home</a>
</div>
<div class="menu2">
<a href="#" class=
"button button-prim button-round button-small" />Button</a>
</div>
</div>
</div>
</body>
</html>
CSS代码:
* {
margin: 0px;
padding: 0px;
font-family: Arial, Helvetica, Sans-serif;
font-size: 12px;
}
body a, body a:hover {
text-decoration: none;
}
.navigation-main {
background-color: #1f2124;
height : 59px;
border-bottom : 0px;
padding-left: auto;
padding-right: auto;
width: 100%;
}
#wrapper {
margin-left : auto;
margin-right : auto;
width : 100%;
padding-top : 0px;
padding-bottom : 0px;
}
.logo {
width : 125px;
position: relative;
top: 10px;
margin-left: 20px;
}
.logo img {
width : 38px;
height : 38px;
}
#menu a {
color: #FFFFFF;
text-decoration: none;
font-size: 14px;
padding-top: 19px;
padding-bottom: 22px;
position: relative;
left: 70px;
bottom: 20px;
padding-left: 10px;
padding-right: 10px;
}
#menu2 a {
color: #FFFFFF;
text-decoration: none;
font-size: 14px;
padding-top: 19px;
padding-bottom: 22px;
position: relative;
left: 1200px;
bottom: 50px;
}
.menu2 {
float: right;
}
#menu a:hover {
background-color: #2c97de;
}
.button-small {
height: 35px;
line-height: 31px;
font-size: 13px;
}
.button-round {
border-radius: 38px;
}
.button-prim {
background-color: #2c97de;
}
.button {
display: inline-block;
position: relative;
text-transform: uppercase;
font-size: 15px;
padding: 0 20px;
border-radius: 38px;
color: #fff;
outline: none;
border: 2px solid transparent;
text-shadow: 0 1px 1px rgba(0,0,0,.2);
bottom: 48px;
height: 30px;
line-height: 30px;
margin-right: 20px;
}
你可以将它用于我们的项目。
$(document).ready(function () {
function CloseNav() {
$(".navbar-collapse").stop().animate({'height': 0},300, function () {
$('.navbar-collapse').removeClass('in').addClass("collapse");
});
$(".navbar-toggle").stop().removeClass('collapsed');
}
$('html').click(function (event) {
var clickover = $(event.target);
var _opened = $(".navbar-collapse").hasClass("navbar-collapse in");
if (_opened === true && !clickover.hasClass("navbar-toggle")) {
CloseNav();
}
});
});
<div class="wrapper">
<div class="navbar navbar-default" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle"data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Project name</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li><a href="#">Link</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li class="divider"></li>
<li class="dropdown-header">Nav header</li>
<li><a href="#">Separated link</a></li>
<li><a href="#">One more separated link</a></li>
</ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="active"><a href="./">Default</a></li>
<li><a href="../navbar-static-top/">Static top</a></li>
<li><a href="../navbar-fixed-top/">Fixed top</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
.wrapper {width:100%, height:100%;}
GL :-)