gpt4 book ai didi

html - 位置粘附子菜单不滚动

转载 作者:可可西里 更新时间:2023-11-01 13:21:25 25 4
gpt4 key购买 nike

我正在使用 bootstrap v-4 beta2,我想创建带有子菜单的粘性顶部菜单。一切都在桌面上工作,但在移动设备上,当我单击打开子菜单时,我看不到整个子菜单,当我滚动整个网站而不是菜单时。我发现我必须对 li.dropdown 做些什么——当我添加绝对位置时,它变得有点乱,但我看到了菜单。但是我不能得到我应该做的。这是代码:

li.dropdown:hover>.dropdown-menu {
display: block;
}

li.dropdown {
position: static;
}

.multi-columns {
width: 100%;
}
<div class="nav-wrapper sticky-top">
<div class="container">
<nav class="navbar navbar-expand-lg navbar-light text-uppercase">
<a class="navbar-brand" href="/"></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="index.html">Domov <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="blog.html">Blog</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="eshop.html">E-shop</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">Dropdown</a>
<div class="dropdown-menu multi-columns">
<div class="row">
<div class="col-md-3">
<h3 class="h5">Blog</h3>
<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 class="col-md-3">
<h3 class="h5">Blog 2</h3>
<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 class="col-md-3">
<h3 class="h5">Blog 3</h3>
<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 class="col-md-3">
<h3 class="h5">Blog 4</h3>
<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>
</div>
</li>
</ul>
<form action="" class="form-inline">
<select class="select2 form-control" style="width: 100%;">

</select>
</form>
</div>
</nav>
<!-- /.nav -->
</div>
<!-- /.container -->
</div>
<!-- /.nav-wrapper -->

此外,在桌面上,当我将鼠标悬停在“下拉菜单”上时,它会显示出来,但当我将鼠标放在子菜单上时,它会消失。我应该移动带有 margin-top: -10px 或 smh 的子菜单吗?或者有什么解决办法吗?

编辑

最主要的是子菜单大于视口(viewport),然后我根本无法在上面滚动

最佳答案

如果您需要子菜单在内容中滚动,为此您需要指定max-heightoverflow: scroll;

您还需要在 dropdown-menu 多列 分区内将 col-md-3 更改为 col-lg-3

CSS

@media (max-width: 991px){
.multi-columns{
max-height: 300px;
overflow: auto;
}
}

演示片段:

li.dropdown:hover>.dropdown-menu {
display: block;
}

li.dropdown {
position: static;
}

.multi-columns {
width: 100%;
}
@media (max-width: 991px){
.multi-columns{
max-height: 300px;
overflow: auto;
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-beta/js/bootstrap.min.js"></script>


<div class="nav-wrapper sticky-top">
<div class="container">
<nav class="navbar navbar-expand-lg navbar-light text-uppercase">
<a class="navbar-brand" href="/"></a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="index.html">Domov <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="blog.html">Blog</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="eshop.html">E-shop</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">Dropdown</a>
<div class="dropdown-menu multi-columns">
<div class="row">
<div class="col-lg-3">
<h3 class="h5">Blog</h3>
<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 class="col-lg-3">
<h3 class="h5">Blog 2</h3>
<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 class="col-lg-3">
<h3 class="h5">Blog 3</h3>
<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 class="col-lg-3">
<h3 class="h5">Blog 4</h3>
<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>
</div>
</li>
</ul>
<form action="" class="form-inline">
<select class="select2 form-control" style="width: 100%;">

</select>
</form>
</div>
</nav>
<!-- /.nav -->
</div>
<!-- /.container -->
</div>
<!-- /.nav-wrapper -->

希望对您有所帮助。 Codepen demo link.谢谢。

关于html - 位置粘附子菜单不滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47017147/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com