我有一个下拉式导航菜单(使用w3schools的css),可以正常工作,直到紧接着放置轮播。然后下拉列表不再显示,我也不知道为什么。我是CSS HTML ..的新手,所以找不到我的问题的解决方案。我已经更改了Z-index和多个类的位置,但不能解决问题。每当我删除引导CSS链接时,下拉菜单就会再次起作用。你有什么建议吗?谢谢!
ps:我把所有代码都放了,抱歉,如果我添加了超出要求的部分,这是我第一次发布
/* CSS Document */
* {
box-sizing: border-box;
font-family: Arial, Helvetica, sans-serif;
}
body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
}
.background-image {
background-image: linear-gradient(rgba(0, 0, 0, 0.8), rgba(0, 0, 0, 0)), url("../img/header.jpg");
background-position: center;
background-repeat: no-repeat;
background-size: cover;
position: relative;
width: 100%;
}
.header-text {
text-align: center;
color: white;
padding: 30px;
}
/* Add a black background color to the top navigation */
.topnav {
background-color: #333;
overflow: hidden;
}
/* Style the links inside the navigation bar */
.topnav a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
/* Change the color of links on hover */
.topnav a:hover {
background-color: #1C8CE8;
text-decoration: none;
color: black;
}
/* Add an active class to highlight the current page */
.activenav {
background-color: #4F47E1;
color: white;
}
/* Hide the link that should open and close the topnav on small screens */
.topnav .icon {
display: none;
}
/* Dropdown container - needed to position the dropdown content */
.dropdown {
float: left;
overflow: hidden;
}
/* Style the dropdown button to fit inside the topnav */
.dropdown .dropbtn {
font-size: 17px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font-family: inherit;
margin: 0;
}
/* Style the dropdown content (hidden by default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
}
/* Style the links inside the dropdown */
.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
/* Add a dark background on topnav links and the dropdown button on hover */
.topnav a:hover,
.dropdown:hover .dropbtn {
background-color: #555;
color: white;
}
/* Add a grey background to dropdown links on hover */
.dropdown-content a:hover {
background-color: #ddd;
color: black;
}
/* Show the dropdown menu when the user moves the mouse over the dropdown button */
.dropdown:hover .dropdown-content {
display: block;
}
.carousel {
max-width: 100% !important;
display: block;
margin-left: auto;
margin-right: auto;
}
.carousel-inner>.item>img {
height: 600px!important;
width: 100%;
}
/* When the screen is less than 600 pixels wide, hide all links, except for the first one ("Home"). Show the link that contains should open and close the topnav (.icon) */
@media screen and (max-width: 600px) {
.topnav a:not(:first-child),
.dropdown .dropbtn {
display: none;
}
.topnav a.icon {
float: right;
display: block;
}
}
/* The "responsive" class is added to the topnav with JavaScript when the user clicks on the icon. This class makes the topnav look good on small screens (display the links vertically instead of horizontally) */
@media screen and (max-width: 600px) {
.topnav.responsive {
position: relative;
}
.topnav.responsive a.icon {
position: absolute;
right: 0;
top: 0;
}
.topnav.responsive a {
float: none;
display: block;
text-align: left;
}
.topnav.responsive .dropdown {
float: none;
}
.topnav.responsive .dropdown-content {
position: relative;
}
.topnav.responsive .dropdown .dropbtn {
display: block;
width: 100%;
text-align: left;
}
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
<nav class="topnav" id="myTopnav">
<a href="#home" class="activenav">Home</a>
<div class="dropdown">
<button class="dropbtn">Products
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
<a href="#">Make</a>
<a href="#">Model</a>
<a href="#">Year</a>
</div>
</div>
<a href="#news">News</a>
<a href="#about">About</a>
<a href="#contactus">Contact us</a>
<a href="javascript:void(0);" class="icon" onclick="Functionnav()"><i class="fa fa-bars"></i></a>
</nav>
<section id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="item active">
<img src="img/img1slideshow.jpg" alt="Chania">
<div class="carousel-caption">
<h3>title</h3>
<p>paragraph</p>
</div>
</div>
<div class="item">
<img src="img/img2slideshow.jpg" alt="Chania">
<div class="carousel-caption">
<h3>title</h3>
<p>paragraph</p>
</div>
</div>
<div class="item">
<img src="img/img3slideshow.jpg" alt="Chania">
<div class="carousel-caption">
<h3>title</h3>
<p>paragraph</p>
</div>
</div>
</div>
菜单包装中css属性溢出的问题。使用下面的代码,希望对您有所帮助
.dropdown {overflow: initial;}
.topnav {
overflow: visible;
width: 100%;
height: 53px;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句