gpt4 book ai didi

html - 如何使用 Bootstrap 获得单个下拉列表

转载 作者:太空宇宙 更新时间:2023-11-04 02:09:31 26 4
gpt4 key购买 nike

我正在为我的导航栏使用 boostrap。我们现在被要求调整我们的代码,我发现需要在其中一个导航项上有一个下拉菜单,但是我正在努力让它适应 Bootstrap 导航栏并让它正确显示。

我正在努力做到这一点,以便在“个人资料”旁边有一个带有下拉菜单的插入符号,悬停时会显示 2 个链接,目前我已将其放在个人资料位置的占位符中。

<!DOCTYPE html>
<html lang="en">
<head>
<title> Home </title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="General.CSS">
<link rel="stylesheet" href="Blog.CSS">
<link href="https://fonts.googleapis.com/css?family=Lato:300,400" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<!-- NavBar -->
<nav class="navbar navbar-inverse">
<article class="container-fluid">
<article class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="NavTitle" href="Home.html">John Doe</a>
</article>
<article class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<ul class="dropdown-menu">
<li><a href="Home.html"> Home </a></li>
<li><a href="Profile.html"> Profile </a></li>
<li><a href="Contact.html"> Contact </a></li>
<li><a href="Tutorial.html"> Tutorial </a></li>
<li><a href="Blog.html"> Blog </a></li>
</ul>
</li>
<li><a href="Home.html"> Home </a></li>
<li><a href="Profile.html" > Profile </a>
<div class="dropdownList">
<span class="caret"></span>
<div class="dropdownContent">
<h5> <a href="Profile.html"> Profile </a> </h5>
<h5> <a href="Profile.html"> Profile </a> </h5>
</div>
</div>
</li>
<li><a href="Contact.html"> Contact </a></li>
<li><a href="Blog.html"> Blog </a></li>
</ul>
</article>
</article>
</nav>
</body>

博客 CSS:

.dropdownList {
display: inline-block;
}

.dropdownContent {
display: none;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
padding: 12px 16px;
z-index: 1;
}

.dropdownList:hover .dropdownContent {
display: block;
}

通用 CSS:

.navbar {
border-radius:0px;
font-family:'Lato', sans-serif;
margin-bottom:0px;
}

.NavTitle {
color:white;
letter-spacing:20px;
font-size:30px;
}

.navbar-header {
text-decoration:none;
}

.navbar a:hover {
text-decoration:none;
color:white;
}

.navbar-nav>li>a {
color:white !important;
font-size:15px;
}

.navbar ul {
list-style-type:none;
}

.navbar li a:hover {
background-color:#009999 !important;
color:white;
}

最佳答案

在 Bootstrap 3 中创建下拉菜单的方法是将下拉类添加到菜单项中。在您的标记中,我看到您有下拉菜单的标记,但您没有使用它。这是一个向您展示其工作原理的示例:

例子:

  /* BLOG CSS */
.dropdownList {
display: inline-block;
}

.dropdownContent {
display: none;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
padding: 12px 16px;
z-index: 1;
}

.dropdownList:hover .dropdownContent {
display: block;
}

/* GENERAL CSS */
.navbar {
border-radius:0px;
font-family:'Lato', sans-serif;
margin-bottom:0px;
}

.NavTitle {
color:white;
letter-spacing:20px;
font-size:30px;
}

.navbar-header {
text-decoration:none;
}

.navbar a:hover {
text-decoration:none;
color:white;
}

.navbar-nav>li>a {
color:white !important;
font-size:15px;
}

.navbar ul {
list-style-type:none;
}

.navbar li a:hover {
background-color:#009999 !important;
color:white;
}
<!DOCTYPE html>
<html lang="en">
<head>
<title> Home </title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="General.CSS">
<link rel="stylesheet" href="Blog.CSS">
<link href="https://fonts.googleapis.com/css?family=Lato:300,400" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<!-- NavBar -->
<nav class="navbar navbar-inverse">
<article class="container-fluid">
<article class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="NavTitle" href="Home.html">John Doe</a>
</article>
<article class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav navbar-right">
<li><a href="Home.html"> Home </a></li>
<li class="dropdown">
<a href="Profile.html" data-toggle="dropdown" class="dropdown-toggle"> Profile<span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="Profile.html"> Profile </a></li>
<li><a href="Profile.html"> Profile </a></li>
</ul>
</li>
<li><a href="Contact.html"> Contact </a></li>
<li><a href="Blog.html"> Blog </a></li>
</ul>
</article>
</article>
</nav>
</body>

如果您希望在将鼠标悬停在下拉菜单上时显示选项,我建议您看一下这个问题,例如: How to make twitter bootstrap menu dropdown on hover rather than click

关于html - 如何使用 Bootstrap 获得单个下拉列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40030973/

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