gpt4 book ai didi

html - 如何在 bootstrap 3 中将下拉菜单放入另一个下拉菜单?

转载 作者:行者123 更新时间:2023-11-28 02:23:10 25 4
gpt4 key购买 nike

我正在为移动设备设计一个侧边栏,并尝试使用 bootstrap 3 在另一个下拉列表中创建一个下拉列表,但我不明白,我不明白会发生什么。

当我尝试访问另一个下拉菜单时,两个下拉菜单都关闭了,我不知道该怎么做。

我认为这是 css 问题,但我不知道会发生什么。

//function sidebar
window.onload = function() {
window.jQuery ? $(document).ready(function() {
$(".sidebarNavigation .navbar-collapse").hide().clone().appendTo("body").removeAttr("class").addClass("sideMenu").show(), $("body").append("<div class='overlay'></div>"), $(".navbar-toggle").on("click", function() {
$(".sideMenu").addClass($(".sidebarNavigation").attr("data-sidebarClass")), $(".sideMenu, .overlay").toggleClass("open"), $(".overlay").on("click", function() {
$(this).removeClass("open"), $(".sideMenu").removeClass("open")
})
}), $(window).resize(function() {
$(".navbar-toggle").is(":hidden") ? $(".sideMenu, .overlay").hide() : $(".sideMenu, .overlay").show()
})
}) : console.log("sidebarNavigation Requires jQuery")
};

$(document).ready(function() {
// dropdown animation
$('.dropdown').on('show.bs.dropdown', function(e) {
$(this).find('.dropdown-menu').first().stop(true, true).slideDown(250);
});
$('.dropdown').on('hide.bs.dropdown', function(e) {
$(this).find('.dropdown-menu').first().stop(true, true).slideUp(0);
});
});
.overlay,
.sideMenu {
position: fixed;
bottom: 0
}

.overlay {
top: 0;
left: -100%;
right: 100%;
margin: auto;
background-color: rgba(0, 0, 0, .4);
z-index: 998;
transition: all ease 20ms
}

.sideMenu,
.sidebarNavigation {
z-index: 999;
margin-bottom: 0
}

.overlay.open {
left: 0;
right: 0
}

.sidebarNavigation .left-navbar-toggle {
float: left;
margin-right: 0;
margin-left: 15px
}

.sideMenu {
left: -100%;
top: 52px;
transition: all ease-in-out .4s;
overflow: hidden;
width: 100%;
max-width: 50%
}

.sideMenu.open {
left: 0;
display: block;
overflow-y: auto
}

.sideMenu ul {
margin: 0
}

.navbar-inverse .navbar-toggle:hover,
.navbar-inverse .navbar-toggle:focus {
background-color: #69306d;
}

.navbar .navbar-toggle {
background-color: #91209a;
border-color: #8f4195;
}

.navbar-inverse .navbar-nav>li>a {
color: #fff;
}

.navbar-inverse .navbar-nav>.active>a,
.navbar-inverse .navbar-nav>.active>a:hover,
.navbar-inverse .navbar-nav>.active>a:focus {
color: #fff;
background-color: #91209a;
}

.navbar-inverse .navbar-nav>.open>a,
.navbar-inverse .navbar-nav>.open>a:hover,
.navbar-inverse .navbar-nav>.open>a:focus {
background-color: #91209a;
color: #fff;
}

.navbar-inverse .navbar-nav .open .dropdown-menu>li>a {
color: #fff;
}

.carousel-control i {
position: relative !important;
}

.open>.dropdown-menu {
-webkit-transform: scale(1, 1);
transform: scale(1, 1);
}

.dropdown-menu {
-webkit-transform-origin: top;
transform-origin: top;
-webkit-animation-fill-mode: forwards;
animation-fill-mode: forwards;
-webkit-transform: scale(1, 0);
display: block;
transition: all 0.2s ease-out;
-webkit-transition: all 0.2s ease-out;
}

.dropdown .dropdown-toggle:after {
display: none;
}

.navbar-inverse .navbar-nav>li>a {
padding-top: 10px !important;
padding-bottom: 10px !important;
padding-left: 15px !important;
}

.navbar-inverse .navbar-nav .open .dropdown-menu>li>a {
padding-top: 10px !important;
padding-bottom: 10px !important;
padding-left: 25px !important;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">

<nav class="navbar navbar-inverse sidebarNavigation" data-sidebarClass="navbar-inverse" style="background-color: #904296;border-color:#904296;border-color: #8f4195;position:fixed;top:0px;width: 100%;">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle left-navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" style="color:white;" href="#">My sidebar</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar" style="background-color: #8f4195;border-color:#8f4195;">
<ul class="nav navbar-nav animated">
<li><a href="#">Home</a></li>
<li class="dropdown"><a href="#" id="drop2" data-toggle="dropdown" class="dropdown-toggle test" role="button">About <b class="caret"></b></a>
<ul role="menu" class="dropdown-menu" aria-labelledby="drop2">
<li class="dropdown"><a href="#" id="drop2" data-toggle="dropdown" class="dropdown-toggle test" role="button">About <b class="caret"></b></a>
<ul role="menu" class="dropdown-menu" aria-labelledby="drop2">
<li role="presentation"><a href="#" role="menuitem">Taaaaa</a></li>
<li role="presentation"><a href="#" role="menuitem">Caaaaers</a></li>
<li role="presentation"><a href="#" role="menuitem">aaaaaars</a></li>
</ul>
</li>
<li role="presentation"><a href="#" role="menuitem">Team Bios</a></li>
<li role="presentation"><a href="#" role="menuitem">Customers</a></li>
<li role="presentation"><a href="#" role="menuitem">Careers</a></li>
</ul>
</li>

</ul>

</div>
</div>
</nav>

最佳答案

试试这个

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
body {
font-family: "Lato", sans-serif;
}

/* Fixed sidenav, full height */
.sidenav {
height: 100%;
width: 200px;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: #111;
overflow-x: hidden;
padding-top: 20px;
}

/* Style the sidenav links and the dropdown button */
.sidenav a, .dropdown-btn {
padding: 6px 8px 6px 16px;
text-decoration: none;
font-size: 20px;
color: #818181;
display: block;
border: none;
background: none;
width: 100%;
text-align: left;
cursor: pointer;
outline: none;
}

/* On mouse-over */
.sidenav a:hover, .dropdown-btn:hover {
color: #f1f1f1;
}

/* Main content */
.main {
margin-left: 200px; /* Same as the width of the sidenav */
font-size: 20px; /* Increased text to enable scrolling */
padding: 0px 10px;
}

/* Add an active class to the active dropdown button */
.active {
background-color: green;
color: white;
}

/* Dropdown container (hidden by default). Optional: add a lighter background color and some left padding to change the design of the dropdown content */
.dropdown-container {
display: none;
background-color: #262626;
padding-left: 8px;
}

/* Optional: Style the caret down icon */
.fa-caret-down {
float: right;
padding-right: 8px;
}

/* Some media queries for responsiveness */
@media screen and (max-height: 450px) {
.sidenav {padding-top: 15px;}
.sidenav a {font-size: 18px;}
}
</style>
</head>
<body>

<div class="sidenav">
<a href="#about">About</a>
<a href="#services">Services</a>
<a href="#clients">Clients</a>
<a href="#contact">Contact</a>
<button class="dropdown-btn">Dropdown
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-container">
<a href="#">Link 1</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
<button class="dropdown-btn">Dropdown
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-container">
<a href="#">Link 1</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
</div>
</div>
<a href="#contact">Search</a>
</div>

<div class="main">
<h2>Sidebar Dropdown</h2>
<p>Click on the dropdown button to open the dropdown menu inside the side navigation.</p>
<p>This sidebar is of full height (100%) and always shown.</p>
<p>Some random text..</p>
</div>

<script>
/* Loop through all dropdown buttons to toggle between hiding and showing its dropdown content - This allows the user to have multiple dropdowns without any conflict */
var dropdown = document.getElementsByClassName("dropdown-btn");
var i;

for (i = 0; i < dropdown.length; i++) {
dropdown[i].addEventListener("click", function() {
this.classList.toggle("active");
var dropdownContent = this.nextElementSibling;
if (dropdownContent.style.display === "block") {
dropdownContent.style.display = "none";
} else {
dropdownContent.style.display = "block";
}
});
}
</script>

</body>
</html>

关于html - 如何在 bootstrap 3 中将下拉菜单放入另一个下拉菜单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56133072/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com