我的移动下拉菜单出现了奇怪的问题。单击切换按钮时,菜单会在按钮下方短暂滚动,然后移动到正确的位置。
它也不总是运行,有时点击它没有效果。
您可以通过查看此页面的移动版本(其右上角的汉堡包图标激活的菜单)看到它的实际效果:
http://u1f8aki.nixweb23.dandomain.dk
以下是创建菜单的代码:
<div class="mobilenav">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="primary-menu"><?php esc_html_e( '', 'mentordanmark' ); ?>
<span class="icon-bar top-bar"></span>
<span class="icon-bar middle-bar"></span>
<span class="icon-bar bottom-bar"></span>
</button>
<div id="navbar" class="navbar-collapse collapse">
<?php
wp_nav_menu( array(
'theme_location' => 'menu-1',
'menu_id' => 'primary-menu-nav',
'container_class' => 'mobileDropdownmenu',
'menu_id' => ' ',
) );
?>
</div>
<div id="blivMentorMenu" class="BlivMentor-Login-Menu" style="display: none">
<?php wp_nav_menu(
'menu=secondary-menu&after=<li class="menu-divider">|</li>'
); ?>
</div>
和CSS:
/* To get the menu to appear */
button.navbar-toggle.collapsed {
display: flex;
flex-direction: column;
}
button.navbar-toggle {
display: flex;
flex-direction: column;
margin-left: 2em;
}
.mobilenav {
display: flex;
align-items: center;
justify-content: space-between;
height: 5.7em;
width: 100%;
}
#primary-menu-nav {
width: 100%;
position: absolute;
left: 0;
top: 5.7em;
border-bottom: 1px solid #e0e4ea;
padding-top: 4em;
}
#primary-menu-nav a {
margin: 0;
padding: 1em;
min-width: 15em;
text-align: center;
}
button.menu-toggle {
border: 0;
font-size: 20px;
width: 1em;
height: 1em;
position: absolute;
top: 1.4em;
overflow: hidden !important;
}
button.menu-toggle:active, button.menu-toggle:focus, a.btn-navbar:active, a.btn-navbar:focus {
border: 0 !important;
outline: 0;
}
a.btn-navbar {
display: flex;
position: absolute;
top: 2.5em;
height: 3em;
width: 3em;
padding: .3em 0;
flex-direction: column;
}
span.icon-bar {
background: #000;
height: .3em;
width: 100%;
margin: .2em;
}
答案 0 :(得分:1)
如果要使用Bootstrap 4 css,则需要使用Bootstrap 4代码。
Bootstrap 3代码与Bootstrap 4 css不兼容。
这是基本的Bootstrap 4导航栏的样子:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Disabled</a>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</nav>