我有一个Bootstrap / Popper.js下拉菜单,当页面高度小于下拉菜单时(即,当高度降低到该菜单不再适合的高度时),该菜单会被推到页面顶部在页面上。)
而不是像现在那样将整个下拉菜单上推至页面顶部,我希望它保持原样。我该怎么办?
例如:
当页面高度允许下拉菜单适合时
如果页面高度太小而下拉菜单无法容纳
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<div class="dropdown custom-drop hide">
<a class="btn float-right btn-secondary btn-lg dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Menu
</a>
<div class="dropdown-menu" aria-labelledby="dropdownMenuLink">
<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>
<style>
.dropdown {
position: absolute;
z-index: 99;
width: calc(100% - 320px);
top: 100px;
right: 0px;
}
.dropdown-toggle {
margin-right: 50px;
}
.dropdown-menu {
position: absolute;
text-align: center;
z-index: 999;
width: calc(100% + 320px);
}
.dropdown-item {
padding: 0.75rem 1.5rem;
width: 100%;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js" integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
</body>
</html>