我在一个网站上工作,我从Bootstrap网站上的仪表板示例开始。但是,当我在导航栏中添加一个下拉菜单时,它会留在导航栏中并破坏整个内容。我无法弄清楚导致此问题的样式。该代码似乎太多了,无法粘贴到这里,所以我将其放入Codepen中:
https://codepen.io/andersmmg/pen/wOgmby
这是为了使仪表板样式正常工作而添加的css:
body {
font-size: .875rem;
}
.feather {
width: 16px;
height: 16px;
vertical-align: text-bottom;
}
/*
* Sidebar
*/
.sidebar {
position: fixed;
top: 0;
bottom: 0;
left: 0;
z-index: 100; /* Behind the navbar */
padding: 48px 0 0; /* Height of navbar */
box-shadow: inset -1px 0 0 rgba(0, 0, 0, .1);
}
.sidebar-sticky {
position: relative;
top: 0;
height: calc(100vh - 48px);
padding-top: .5rem;
overflow-x: hidden;
overflow-y: auto; /* Scrollable contents if viewport is shorter than content. */
}
@supports ((position: -webkit-sticky) or (position: sticky)) {
.sidebar-sticky {
position: -webkit-sticky;
position: sticky;
}
}
.sidebar .nav-link {
font-weight: 500;
color: #333;
}
.sidebar .nav-link .feather {
margin-right: 4px;
color: #999;
}
.sidebar .nav-link.active {
color: #007bff;
}
.sidebar .nav-link:hover .feather,
.sidebar .nav-link.active .feather {
color: inherit;
}
.sidebar-heading {
font-size: .75rem;
text-transform: uppercase;
}
/*
* Content
*/
[role="main"] {
padding-top: 48px; /* Space for fixed navbar */
}
/*
* Navbar
*/
.navbar-brand {
padding-top: .75rem;
padding-bottom: .75rem;
font-size: 1rem;
background-color: rgba(0, 0, 0, .25);
box-shadow: inset -1px 0 0 rgba(0, 0, 0, .25);
}
.navbar .form-control {
padding: .75rem 1rem;
border-width: 0;
border-radius: 0;
}
.navbar .form-control::placeholder {
color: white;
}
.navbar .form-control:focus::placeholder {
color: rgba(0, 0, 0, 0.46);
}
.form-control-dark {
color: #fff;
background-color: rgba(255, 255, 255, .1);
border-color: rgba(255, 255, 255, .1);
}
.form-control-dark:focus {
border-color: transparent;
box-shadow: 0 0 0 3px rgba(255, 255, 255, .25);
}
最佳答案
我刚刚删除了下拉菜单中的代码,并用文档中的代码示例替换了代码,并且下拉菜单现在可以正常运行。我认为您的某些代码不允许下拉列表存在于其容器之外,这导致其父容器扩展(即ul
和li
元素)
<nav class="navbar navbar-dark fixed-top bg-dark flex-md-nowrap p-0 shadow">
<a class="navbar-brand col-sm-3 col-md-2 mr-0" href="index.php">Store Manager</a>
<input class="form-control form-control-dark w-100" type="text" placeholder="Search" aria-label="Search">
<div class="dropdown dropleft">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
andersmmg
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</div>
</nav>
您仍然需要将按钮样式设置为所需的颜色,但是功能仍然存在。我更改了菜单以使其显示在左侧(
dropleft
),因此它不会在页面上显示。您可以看到我的Fiddle of working solution here。希望能有所帮助。关于css - 导航栏内部的Bootstrap导航栏下拉菜单,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55029499/