I'm trying to customise Bootstrap 4 navbar and its contents...my task is to add more nav items on drop down menu. the problems comes when i wrap container fluid elements in drop down items with its default CSS style (position absolute) the container fluid elements loses layout on large screen size .
I will be grateful for any help you can provide to fix my code
<!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/[email protected]/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 >
<a href="#">Navbar</a>
<button type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span ></span>
</button>
<div id="navbarSupportedContent">
<ul >
<li >
<a href="#">Home <span >(current)</span></a>
</li>
<li >
<a href="#">Link</a>
</li>
<li >
<a href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown
</a>
<div aria-labelledby="navbarDropdown">
<div >
<div >
<div >
<ul >
<li > <a href="#">One Page</a></li>
<li > <a href="#">Portfolio</a></li>
<li > <a href="#">Construction</a></li>
<li > <a href="#">Business</a></li>
<li > <a href="#">Landing page</a></li>
</ul>
</div>
<div >
<ul >
<li > <a href="#">Personal</a></li>
<li > <a href="#">Transportation</a></li>
<li > <a href="#">Education</a></li>
<li > <a href="#">Corperate</a></li>
<li > <a href="#">Resume</a></li>
</ul>
</div>
<div >
<ul >
<li > <a href="#">Health</a></li>
<li > <a href="#">Admin</a></li>
<li > <a href="#">Agency</a></li>
<li > <a href="#">Real Estate</a></li>
</ul>
</div>
<div >
<ul >
<li > <a href="#">Movies</a></li>
<li > <a href="#">Sport & Entertainement</a></li>
<li > <a href="#">Nature</a></li>
<li > <a href="#">Photography</a></li>
<li > <a href="#">Resaurant</a></li>
<li > <a href="#">Medical</a></li>
</ul>
</div>
<div >
<ul >
<li > <a href="#">Movies</a></li>
<li > <a href="#">Sport & Entertainement</a></li>
<li > <a href="#">Nature</a></li>
<li > <a href="#">Photography</a></li>
<li > <a href="#">Resaurant</a></li>
<li > <a 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/[email protected]/dist/umd/popper.min.js" integrity="sha384-ApNbgh9B Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5 76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>
CodePudding user response:
You need to write media query to handle it or add a extra class to dropdown as I did.
<!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/[email protected]/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;
}
.flex-1{
flex:1;
width: 100%;
}
</style>
<title>Hello, world!</title>
</head>
<body>
<nav >
<a href="#">Navbar</a>
<button type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span ></span>
</button>
<div id="navbarSupportedContent">
<ul >
<li >
<a href="#">Home <span >(current)</span></a>
</li>
<li >
<a href="#">Link</a>
</li>
<li >
<a href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown
</a>
<div aria-labelledby="navbarDropdown">
<div >
<div >
<div >
<ul >
<li > <a href="#">One Page</a></li>
<li > <a href="#">Portfolio</a></li>
<li > <a href="#">Construction</a></li>
<li > <a href="#">Business</a></li>
<li > <a href="#">Landing page</a></li>
</ul>
</div>
<div >
<ul >
<li > <a href="#">Personal</a></li>
<li > <a href="#">Transportation</a></li>
<li > <a href="#">Education</a></li>
<li > <a href="#">Corperate</a></li>
<li > <a href="#">Resume</a></li>
</ul>
</div>
<div >
<ul >
<li > <a href="#">Health</a></li>
<li > <a href="#">Admin</a></li>
<li > <a href="#">Agency</a></li>
<li > <a href="#">Real Estate</a></li>
</ul>
</div>
<div >
<ul >
<li > <a href="#">Movies</a></li>
<li > <a href="#">Sport & Entertainement</a></li>
<li > <a href="#">Nature</a></li>
<li > <a href="#">Photography</a></li>
<li > <a href="#">Resaurant</a></li>
<li > <a href="#">Medical</a></li>
</ul>
</div>
<div >
<ul >
<li > <a href="#">Movies</a></li>
<li > <a href="#">Sport & Entertainement</a></li>
<li > <a href="#">Nature</a></li>
<li > <a href="#">Photography</a></li>
<li > <a href="#">Resaurant</a></li>
<li > <a 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/[email protected]/dist/umd/popper.min.js" integrity="sha384-ApNbgh9B Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5 76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>