Issue
I have a drop-down menu on the top navigation. I have applied bootstrap to one of my page, however because of this the drop down menu does not work.
Applied to Head:
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
Applied to Body:
<div class="topnav" id="myTopnav">
<div class="topnav-left">
<a href="/"><img src="Img/Signature-Black.png"></a>
</div>
<a href="./contact.html">Contact</a>
<a href="./about.html"> About</a>
<div class="dropdown">
<button class="dropbtn">Blog <i class="fa fa-caret-down"></i></button>
<div class="dropdown-content">
<a href="#">Link 1</a>
<a href="#">Link 2</a>
</div>
</div>
<a href="./photos.html">Photos</a>
<a href="javascript:void(0);" class="icon" onclick="myFunction()">
<i class="fa fa-bars"></i>
</a>
</div>
<script>
function myFunction() {
var x = document.getElementById("myTopnav");
if (x.className === "topnav") {
x.className += " responsive";
} else {
x.className = "topnav";
}
}
</script>
My external CSS for the navigation bar:
.topnav {
overflow: hidden;
background-color: transparent;
z-index: 100;
align-items: center;
top: 0;
left: 0;
width: 100%;
padding: 30px 10%;
}
.topnav a {
float: right;
color: black;
text-align: center;
padding: 10px 20px;
text-decoration: none;
font-size: 18px;
font-weight: 500;
margin-right: 35px;
transition: 1s;
}
.topnav .icon {
display: none;
position: fixed;
right: 7%;
top: 30px;
}
.topnav .icon:hover {
color: #daa520;
}
.topnav-left {
float: left;
}
/* Dropdown */
.dropdown {
float: right;
overflow: hidden;
}
.dropdown .dropbtn {
font-size: 18px;
font-weight: 500;
border: none;
outline: none;
color: rgb(0, 0, 0);
padding: 10px 20px;
background-color: inherit;
font-family: inherit;
margin-right: 35px;
}
/* Dropdown + other menu hover */
.topnav a:hover, .dropdown:hover .dropbtn {
color: #daa520;
transition: 1s;
}
.dropdown-content {
display: none;
position: absolute;
background-color: transparent;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {
color: #daa520;
}
.dropdown:hover .dropdown-content {
display: block;
}
/* Resize Screen */
@media screen and (max-width: 900px) {
.topnav a:not(:first-child), .dropdown .dropbtn {
display: none;
}
.topnav a.icon {
float: right;
display: block;
}
.topnav-left {
float: left;
}
}
@media screen and (max-width: 900px) {
.topnav.responsive {position: relative;}
.topnav.responsive .icon {
position: fixed;
right: 7%;
top: 30px;
}
.topnav.responsive a {
float: none;
display: block;
text-align: left;
}
.topnav.responsive .topnav-left {
float: none;
}
.topnav.responsive .dropdown {float: none;}
.topnav.responsive .dropdown-content {position: relative;}
.topnav.responsive .dropdown .dropbtn {
display: block;
width: 100%;
text-align: left;
}
}
I am not very familiar with Bootstrap, so I am not exactly sure how it differs from using normal CSS and HTML to create a drop-down list. I hope there is an easy way to fix and keep the applied design for the navigation links, as I don't want to have to rework the site without bootstrap.
I appreciate any help or suggestions. Thank you!
I have tested other pages, so I know the issue is not with the drop-down itself. I have also tried removing bootstrap, and it does work without it, but then it will mess up the rest of the contents on the webpage.
Solution
there is a conflict between your dropdown and the bootstrap dropdown. "dropdwon" is a class name in bootstrap, it use it both in css and js files.
you can try using bootstarp dropdown and change it's style or use different class name
Answered By - Hezy Ziv
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.