英文:
bg color no white in bootstrap
问题
I understand your request. Here's the translated content:
当我在深色导航栏中使用 Bootstrap 5 的下拉菜单时,下拉菜单的背景是黑色的,但在导航栏之外使用时,下拉菜单的背景是白色的,为什么?
我想在深色导航栏中使用白色下拉菜单。
我的完整代码:
MyCode
我的导航栏和下拉菜单:
<nav class="navbar navbar-expand-lg bg-dark " data-bs-theme="dark">
<div class="container-fluid">
<a class="navbar-brand" href="#">Navbar</a>
<ul class="navbar-nav mb-3">
<li class="nav-item dropdown ">
<a class="nav-link dropdown-toggle show" href="#" role="button" data-bs-toggle="dropdown"
aria-expanded="true">
<i class="bi bi-person-fill"></i>
</a>
<ul class="dropdown-menu dropdown-menu-end" data-bs-popper="static">
<li><a class="dropdown-item " href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li>
<hr class="dropdown-divider">
</li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</li>
</ul>
</div>
</nav>
<ul class="navbar-nav mb-3">
<li class="nav-item dropdown ">
<a class="nav-link dropdown-toggle show" href="#" role="button" data-bs-toggle="dropdown"
aria-expanded="true">
<i class="bi bi-person-fill"></i>
</a>
<ul class="dropdown-menu " data-bs-popper="static">
<li><a class="dropdown-item " href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li>
<hr class="dropdown-divider">
</li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</li>
</ul>
请注意,此翻译仅包括代码的翻译部分,不包括回答问题的内容。
英文:
when i use bootstrap5 dropdown in bg-dark navbar, dropdown background is black but use it the outside of navbar, dropdown background is white why?<br>
i want to use white dropdown in dark navbar.<br>
my complete code:
MyCode
my navbar & dropdown:
<nav class="navbar navbar-expand-lg bg-dark " data-bs-theme="dark">
<div class="container-fluid">
<a class="navbar-brand" href="#">Navbar</a>
<ul class="navbar-nav mb-3">
<li class="nav-item dropdown ">
<a class="nav-link dropdown-toggle show" href="#" role="button" data-bs-toggle="dropdown"
aria-expanded="true">
<i class="bi bi-person-fill"></i>
</a>
<ul class="dropdown-menu dropdown-menu-end" data-bs-popper="static">
<li><a class="dropdown-item " href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li>
<hr class="dropdown-divider">
</li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
<ul class="navbar-nav mb-3">
<li class="nav-item dropdown ">
<a class="nav-link dropdown-toggle show" href="#" role="button" data-bs-toggle="dropdown"
aria-expanded="true">
<i class="bi bi-person-fill"></i>
</a>
<ul class="dropdown-menu " data-bs-popper="static">
<li><a class="dropdown-item " href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li>
<hr class="dropdown-divider">
</li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</li>
</ul>
答案1
得分: 0
将Bootstrap类bg-dark
添加到navbar
时,Bootstrap会自适应所有其他元素,以确保用户体验(即用户体验)尽可能好。为什么?如果你有一个深灰色的导航栏,但下拉菜单是白色的,这两种颜色之间的对比太大。然而,如果你希望在深灰色导航栏中有一个白色的下拉菜单,你可以这样做。
添加以下CSS:
.navbar-nav .dropdown-menu {
background-color: white;
}
.navbar-nav .dropdown-item {
color: black;
}
.navbar-nav .dropdown-divider {
border-top: 1px solid black;
}
.navbar-nav .dropdown-item:hover {
background-color: lightgrey;
color: black;
}
查看下面的代码片段:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
.navbar-nav .dropdown-menu {
background-color: white;
}
.navbar-nav .dropdown-item {
color: black;
}
.navbar-nav .dropdown-divider {
border-top: 1px solid black;
}
.navbar-nav .dropdown-item:hover {
background-color: lightgrey;
color: black;
}
<!-- language: lang-html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Dashboard</title>
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KK94CHFLLe+nY2dmCWGMq91rCGa5gtU4mk92HdvYe+M/SXH301p5ILy+dN9+nJOZ" crossorigin="anonymous">
</head>
<body>
<nav class="navbar navbar-expand-lg bg-dark ">
<div class="container-fluid">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<form class="d-flex ms-auto">
<div class="input-group mb-3">
<input type="text" class="form-control" placeholder="Recipient's username" aria-label="Recipient's username" aria-describedby="button-addon2">
<button class="btn btn-outline-secondary" type="button" id="button-addon2"><i class="bi bi-search"></i></button>
</div>
</form>
<ul class="navbar-nav mb-3">
<li class="nav-item dropdown ">
<a class="nav-link dropdown-toggle show" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="true">
<i class="bi bi-person-fill"></i>
</a>
<ul class="dropdown-menu dropdown-menu-end" data-bs-popper="static">
<li><a class="dropdown-item " href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li>
<hr class="dropdown-divider">
</li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
<ul class="navbar-nav mb-3">
<li class="nav-item dropdown ">
<a class="nav-link dropdown-toggle show" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="true">
<i class="bi bi-person-fill"></i>
</a>
<ul class="dropdown-menu " data-bs-popper="static">
<li><a class="dropdown-item " href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li>
<hr class="dropdown-divider">
</li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</li>
</ul>
<script src="js/bootstrap.bundle.min.js"></script>
<script src="js/script.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ENjdO4Dr2bkBIFxQpeoTz1HIcje39Wm4jDKdf19U8gI4ddQ3GYNS7NTKfAdVQSZe" crossorigin="anonymous"></script>
</body>
</html>
<!-- end snippet -->
希望这些翻译对你有帮助。如果有其他问题,请随时提出。
英文:
When you add the Bootstrap class bg-dark
to the navbar
, Bootstrap adapts all other elements so that the UX (i.e., user experience) is the best possible. Why? If you have a dark gray navbar but the dropdown is white, there's too much contrast between these two colors. However, you can have a white dropdown in a dark gray navbar if you want.
Add the following CSS:
.navbar-nav .dropdown-menu {
background-color: white;
}
.navbar-nav .dropdown-item {
color: black;
}
.navbar-nav .dropdown-divider {
border-top: 1px solid black;
}
.navbar-nav .dropdown-item:hover {
background-color: lightgrey;
color: black;
}
See the snippet below.
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
.navbar-nav .dropdown-menu {
background-color: white;
}
.navbar-nav .dropdown-item {
color: black;
}
.navbar-nav .dropdown-divider {
border-top: 1px solid black;
}
.navbar-nav .dropdown-item:hover {
background-color: lightgrey;
color: black;
}
<!-- language: lang-html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Admin Dashboard</title>
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KK94CHFLLe+nY2dmCWGMq91rCGa5gtU4mk92HdvYe+M/SXH301p5ILy+dN9+nJOZ" crossorigin="anonymous">
</head>
<body>
<nav class="navbar navbar-expand-lg bg-dark " data-bs-theme="dark">
<div class="container-fluid">
<a class="navbar-brand" href="#">Navbar</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<form class="d-flex ms-auto">
<div class="input-group mb-3">
<input type="text" class="form-control" placeholder="Recipient's username" aria-label="Recipient's username" aria-describedby="button-addon2">
<button class="btn btn-outline-secondary" type="button" id="button-addon2"><i
class="bi bi-search"></i></button>
</div>
</form>
<ul class="navbar-nav mb-3">
<li class="nav-item dropdown ">
<a class="nav-link dropdown-toggle show" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="true">
<i class="bi bi-person-fill"></i>
</a>
<ul class="dropdown-menu dropdown-menu-end" data-bs-popper="static">
<li><a class="dropdown-item " href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li>
<hr class="dropdown-divider">
</li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
<ul class="navbar-nav mb-3">
<li class="nav-item dropdown ">
<a class="nav-link dropdown-toggle show" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="true">
<i class="bi bi-person-fill"></i>
</a>
<ul class="dropdown-menu " data-bs-popper="static">
<li><a class="dropdown-item " href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li>
<hr class="dropdown-divider">
</li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</li>
</ul>
<script src="js/bootstrap.bundle.min.js"></script>
<script src="js/script.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ENjdO4Dr2bkBIFxQpeoTz1HIcje39Wm4jDKdf19U8gI4ddQ3GYNS7NTKfAdVQSZe" crossorigin="anonymous"></script>
</body>
</html>
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论