我正在尝试使用CSS创建一个响应式菜单,如Bootstrap导航栏。 我有实际的功能工作,但菜单抓取器的位置是错误的,我不太确定如何解决它..抓取器应该与徽标文本内联,红色框应该只出现(带项目在黑色栏下面)
HTML:
<div id="wrapper">
<div id="header" class="clearfix">
<span class="logo">Logo</span>
<input type="checkbox" id="navbar-checkbox" class="navbar-checkbox">
<nav class="nav-menu">
<ul>
<li><a href="index.php">Home</a></li>
<li><a href="history.php">History</a></li>
<li><a href="reviews.php">Reviews</a></li>
<li><a href="#" class="menu-toggle">Menu</a></li>
<li><a href="location.php">Location</a></li>
</ul>
<label for="navbar-checkbox" class="navbar-handle"></label>
</nav>
</div>
</div>
CSS:
@media (min-width: 900px) {
.nav-menu {
font-size: 1em;
}
}
.nav-menu {
padding: 0.5em;
/*background: #eee;*/
/*border: 1px solid red;*/
min-height: 2em;
line-height: 1em;
}
.nav-menu ul {
transition: max-height 0.25s linear;
margin: 0;
padding: 8px 20px 8px;
text-align: center;
text-align: right;
border: 1px solid red;
}
.nav-menu li {
transition: visibility .25s linear;
display: inline-block;
margin: 0 .75em;
border: 1px solid blue;
}
.nav-menu li a {
display: block;
text-transform: uppercase;
padding: .70em 1em;
}
.nav-menu li a:hover {
display: block;
background: #ffed8b;
color: #000;
}
@media (max-width: 650px) {
.nav-menu ul {
max-height: 0;
overflow: hidden;
margin: 0 3.5em 0 1em;
}
.nav-menu li {
visibility: hidden;
display: block;
padding: 0.5em 0.6em;
}
.nav-menu .navbar-handle {
display: block;
float: right;
}
#navbar-checkbox:checked + .nav-menu ul {
max-height: 300px;
}
#navbar-checkbox:checked + .nav-menu li {
visibility: visible;
}
#navbar-checkbox:checked + .nav-menu .navbar-handle,
#navbar-checkbox:checked + .nav-menu .navbar-handle:after,
#navbar-checkbox:checked + .nav-menu .navbar-handle:before {
border-color: #aaa;
}
}
.navbar-checkbox {
display: none;
}
.navbar-handle {
display: none;
cursor: pointer;
position: relative;
font-size: 45px;
padding: .5em 0;
height: 0;
width: 1.6em;
border-top: 0.1em solid;
}
.navbar-handle:before,
.navbar-handle:after {
position: absolute;
left: 0;
right: 0;
content: ' ';
border-top: 0.1em solid;
}
.navbar-handle:before {
top: 0.3em;
}
.navbar-handle:after {
top: 0.8em;
}
.menu {
position: absolute;
top: 0;
left: 0;
right: 0;
}
.menu .navbar-handle {
position: absolute;
font-size: 1.2em;
top: 0.7em;
right: 12px;
z-index: 10;
}
答案 0 :(得分:0)
你错过了CSS中的“-toggle”你有“.menu”它应该看起来像“。menu-toggle”:这里有一些标记让你开始:
/* Your can adjust the CSS however you see fit for your Project */
@media (min-width: 900px) {
.nav-menu {
font-size: 1em;
}
}
.nav-menu {
padding: 0.5em;
/*background: #eee;*/
/*border: 1px solid red;*/
min-height: 2em;
line-height: 1em;
}
.nav-menu ul {
transition: max-height 0.25s linear;
margin: 0;
padding: 8px 20px 8px;
text-align: center;
text-align: right;
border: 1px solid red;
}
.nav-menu li {
transition: visibility .25s linear;
display: inline-block;
margin: 0 .75em;
border: 1px solid blue;
}
.nav-menu li a {
display: block;
text-transform: uppercase;
padding: .70em 1em;
}
.nav-menu li a:hover {
display: block;
background: #ffed8b;
color: #000;
}
@media (max-width: 650px) {
.nav-menu ul {
max-height: 0;
overflow: hidden;
margin: 0 3.5em 0 1em;
}
.nav-menu li {
visibility: hidden;
display: block;
padding: 0.5em 0.6em;
}
.nav-menu .navbar-handle {
display: block;
float: right;
}
#navbar-checkbox:checked + .nav-menu ul {
max-height: 300px;
}
#navbar-checkbox:checked + .nav-menu li {
visibility: visible;
}
#navbar-checkbox:checked + .nav-menu .navbar-handle,
#navbar-checkbox:checked + .nav-menu .navbar-handle:after,
#navbar-checkbox:checked + .nav-menu .navbar-handle:before {
border-color: #aaa;
}
}
.navbar-checkbox {
display: none;
}
.navbar-handle {
display: none;
cursor: pointer;
position: relative;
font-size: 45px;
padding: .5em 0;
height: 0;
width: 1.6em;
border-top: 0.1em solid;
}
.navbar-handle:before,
.navbar-handle:after {
position: absolute;
left: 0;
right: 0;
content: ' ';
border-top: 0.1em solid;
}
.navbar-handle:before {
top: 0.3em;
}
.navbar-handle:after {
top: 0.8em;
}
.menu-toggle { /* Correction Needed To Be Made Here Now You Can Make Adjustments */
position: absolute;
top: 0;
left: 30;
}
.menu .navbar-handle {
position: absolute;
font-size: 1.2em;
top: 0.7em;
right: 12px;
z-index: 10;
}
<html>
<body>
<div id="wrapper">
<div id="header" class="clearfix">
<span class="logo">Logo</span>
<input type="checkbox" id="navbar-checkbox" class="navbar-checkbox">
<nav class="nav-menu">
<ul>
<li><a href="index.php">Home</a></li>
<li><a href="history.php">History</a></li>
<li><a href="reviews.php">Reviews</a></li>
<li><a href="#" class="menu-toggle">Menu</a></li>
<li><a href="location.php">Location</a></li>
</ul>
<label for="navbar-checkbox" class="navbar-handle"></label>
</nav>
</div>
</div>
</body>
</html>