我正试图自定义 Bootstrap 4导航栏及其内容...我的任务是添加更多的下拉菜单导航项目。问题来了,当我 Package 容器流体元素在下拉项目与其默认的CSS样式(绝对位置)容器流体元素失去布局的大屏幕尺寸。
我将感谢您提供的任何帮助来修复我的代码
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<style>
.col-lg-3 {
flex: 0 0 auto;
max-width: 18%;
}
.dropdown-menu {
position: absolute;
top: 100%;
left: 0;
right:0;
z-index: 1000;
display: none;
float: left;
min-width: 10rem;
padding: 0.5rem 0;
margin: 0.125rem 0 0;
font-size: 1rem;
color: #212529;
text-align: left;
list-style: none;
background-color: #fff;
background-clip: padding-box;
border: 1px solid rgba(0, 0, 0, 0.15);
border-radius: 0.25rem;
}
</style>
<title>Hello, world!</title>
</head>
<body>
<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">
<div class="container-fluid">
<div class="row justify-content-center">
<div class="col-lg-3 ">
<ul class="list-unstyled">
<li class="nav-item"> <a class="nav-link" href="#">One Page</a></li>
<li class="nav-item"> <a class="nav-link" href="#">Portfolio</a></li>
<li class="nav-item"> <a class="nav-link" href="#">Construction</a></li>
<li class="nav-item"> <a class="nav-link" href="#">Business</a></li>
<li class="nav-item"> <a class="nav-link" href="#">Landing page</a></li>
</ul>
</div>
<div class="col-lg-3 ">
<ul class="list-unstyled">
<li class="nav-item"> <a class="nav-link" href="#">Personal</a></li>
<li class="nav-item"> <a class="nav-link" href="#">Transportation</a></li>
<li class="nav-item"> <a class="nav-link" href="#">Education</a></li>
<li class="nav-item"> <a class="nav-link" href="#">Corperate</a></li>
<li class="nav-item"> <a class="nav-link" href="#">Resume</a></li>
</ul>
</div>
<div class="col-lg-3 ">
<ul class="list-unstyled">
<li class="nav-item"> <a class="nav-link" href="#">Health</a></li>
<li class="nav-item"> <a class="nav-link" href="#">Admin</a></li>
<li class="nav-item"> <a class="nav-link" href="#">Agency</a></li>
<li class="nav-item"> <a class="nav-link" href="#">Real Estate</a></li>
</ul>
</div>
<div class="col-lg-3">
<ul class="list-unstyled">
<li class="nav-item"> <a class="nav-link" href="#">Movies</a></li>
<li class="nav-item"> <a class="nav-link" href="#">Sport & Entertainement</a></li>
<li class="nav-item"> <a class="nav-link" href="#">Nature</a></li>
<li class="nav-item"> <a class="nav-link" href="#">Photography</a></li>
<li class="nav-item"> <a class="nav-link" href="#">Resaurant</a></li>
<li class="nav-item"> <a class="nav-link" href="#">Medical</a></li>
</ul>
</div>
<div class="col-lg-3">
<ul class="list-unstyled">
<li class="nav-item"> <a class="nav-link" href="#">Movies</a></li>
<li class="nav-item"> <a class="nav-link" href="#">Sport & Entertainement</a></li>
<li class="nav-item"> <a class="nav-link" href="#">Nature</a></li>
<li class="nav-item"> <a class="nav-link" href="#">Photography</a></li>
<li class="nav-item"> <a class="nav-link" href="#">Resaurant</a></li>
<li class="nav-item"> <a class="nav-link" href="#">Medical</a></li>
</ul>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<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://cdn.jsdelivr.net/npm/popper.js@1.12.9/dist/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>
1条答案
按热度按时间41ik7eoe1#
您需要编写媒体查询来处理它,或者像我一样向下拉列表添加一个额外的类。