gpt4 book ai didi

drop-down-menu - 强制引导下拉菜单始终显示在底部并允许它离开屏幕

转载 作者:行者123 更新时间:2023-12-03 15:10:17 25 4
gpt4 key购买 nike

当视口(viewport)底部没有空间容纳下拉菜单时,它会显示在其下拉按钮的顶部。是否有可能改变这种行为并使下拉菜单始终出现在底部?

    <div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown button
</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>

最佳答案

对于 Bootstrap 5 (≥ 5.0)
通过设置 data-bs-display="static" 完全禁用 Popper.js 动态定位在 dropdown-toggle元素(按钮或链接)。
来自 Bootstrap 5 Docs > Dropdowns: Options :

By default, we use Popper.js for dynamic positioning. Disable this with static.



.window {
height: 8em;
overflow: auto;
margin: 1em;
padding: 1em;
border: 10px solid #DFEAF2;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"/>

<div class="window">
<div class="dropdown">
<button data-bs-display="static" class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton1" data-bs-toggle="dropdown" aria-expanded="false">
Dropdown dropdown-toggle with data-bs-display="static"
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuButton1">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</div>
</div>

对于 Bootstrap 4 (4.1 - 4.6)
通过设置 data-display="static" 完全禁用 Popper.js 动态定位在 dropdown-toggle元素(按钮或链接)。
来自 Bootstrap 4 Docs > Dropdowns: Options :

By default, we use Popper.js for dynamic positioning. Disable this with static.



.window {
height: 8em;
overflow: auto;
margin: 1em;
padding: 1em;
border: 10px solid #DFEAF2;
}
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet" />
<div class="window">
<div class="dropdown">
<button data-display="static" class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown dropdown-toggle with data-display="static"
</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>
<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>

关于drop-down-menu - 强制引导下拉菜单始终显示在底部并允许它离开屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47242702/

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