gpt4 book ai didi

html - bootstrap 4 navbar-toggler-icon(汉堡包)显示两行而不是三行

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

我正在使用 bootstrap 4 构建这个导航栏。

导航栏工作正常,但有一个问题我无法自己解决。

在折叠时,汉堡包图标显示两行而不是三行。我不确定汉堡包为什么会这样出现,但我确定它与伪元素有关。

我整个上午都在弄清楚为什么会这样。有人可以看看我的代码,看看我做错了什么吗?

这里是一个链接 fiddle

下面是我的代码的副本

nav {
padding: 20px 0 20px;
margin-bottom: 20px;
margin-top: 20px; }

.navbar {
padding: 0; }

.navbar-toggler:active,
.navbar-toggler:focus {
outline: none; }

.navbar-custom .navbar-toggler-icon {
width: 24px;
height: 17px;
background-image: none;
position: relative;
transition: all 300ms linear; }

.navbar-custom .navbar-toggler-icon:after,
.navbar-custom .navbar-toggler-icon:before {
width: 24px;
position: absolute;
height: 2px;
background-color: #000;
top: 0;
left: 0;
content: '';
z-index: 2;
transition: all 300ms linear; }

.navbar-custom .navbar-toggler-icon:after {
top: 8px; }

.navbar-toggler[aria-expanded="true"] .navbar-toggler-icon:after {
transform: rotate(45deg); }

.navbar-toggler[aria-expanded="true"] .navbar-toggler-icon:before {
transform: translateY(8px) rotate(-45deg); }

.navbar-toggler[aria-expanded="true"] .navbar-toggler-icon {
border-color: transparent; }

.nav-link {
color: #4b4b4b;
font-weight: 500;
transition: all 200ms linear; }

.nav-item:hover .nav-link {
color: #3b3b3b; }

.nav-item.active .nav-link {
color: .nav-item.active .nav-link #c2002d; }

.nav-link {
position: relative;
padding: 5px 0 !important;
display: inline-block; }

.nav-item:after {
position: absolute;
bottom: -5px;
left: 0;
width: 100%;
height: 2px;
content: '';
background-color: #c2002d;
opacity: 0;
transition: all 200ms linear; }

.nav-item:hover:after {
bottom: 0;
opacity: 1; }

.nav-item.active:hover:after {
opacity: 0; }

.nav-item {
position: relative;
margin-left: 50px;
transition: all 200ms linear; }

.navbar-brand > img {
display: block; }
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<title></title>
</head>

<body>
<nav class="navbar navbar-custom navbar-expand-md ">
<button class="navbar-toggler ml-auto" type="button" data-toggle="collapse" data-target="#navbarDropdown" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>

<div class="collapse navbar-collapse" id="navbarDropdown">
<ul class="navbar-nav mx-auto">
<li class="nav-item ">
<a class="nav-link " href="#" >Home</a>
</li>
<li class="nav-item ">
<a class="nav-link" href="#">Browse</a>
</li>
<li class="nav-item ">
<a class="nav-link" href="#">Search</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About</a>
</li>
</ul>
</div>
</nav>






</body>

</html>

最佳答案

您可以将 border-bottom 应用于 .navbar-custom .navbar-toggler-icon 以获得第三行。检查片段。

nav {
padding: 20px 0 20px;
margin-bottom: 20px;
margin-top: 20px; }

.navbar {
padding: 0; }

.navbar-toggler:active,
.navbar-toggler:focus {
outline: none; }

.navbar-custom .navbar-toggler-icon {
width: 24px;
height: 17px;
background-image: none;
position: relative;
transition: all 300ms linear;
border-bottom: solid 2px #000;
}

.navbar-custom .navbar-toggler-icon:after,
.navbar-custom .navbar-toggler-icon:before {
width: 24px;
position: absolute;
height: 2px;
background-color: #000;
top: 0;
left: 0;
content: '';
z-index: 2;
transition: all 300ms linear; }

.navbar-custom .navbar-toggler-icon:after {
top: 8px; }

.navbar-toggler[aria-expanded="true"] .navbar-toggler-icon:after {
transform: rotate(45deg); }

.navbar-toggler[aria-expanded="true"] .navbar-toggler-icon:before {
transform: translateY(8px) rotate(-45deg); }

.navbar-toggler[aria-expanded="true"] .navbar-toggler-icon {
border-color: transparent; }

.nav-link {
color: #4b4b4b;
font-weight: 500;
transition: all 200ms linear; }

.nav-item:hover .nav-link {
color: #3b3b3b; }

.nav-item.active .nav-link {
color: .nav-item.active .nav-link #c2002d; }

.nav-link {
position: relative;
padding: 5px 0 !important;
display: inline-block; }

.nav-item:after {
position: absolute;
bottom: -5px;
left: 0;
width: 100%;
height: 2px;
content: '';
background-color: #c2002d;
opacity: 0;
transition: all 200ms linear; }

.nav-item:hover:after {
bottom: 0;
opacity: 1; }

.nav-item.active:hover:after {
opacity: 0; }

.nav-item {
position: relative;
margin-left: 50px;
transition: all 200ms linear; }

.navbar-brand > img {
display: block; }
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<title></title>
</head>

<body>
<nav class="navbar navbar-custom navbar-expand-md ">
<button class="navbar-toggler ml-auto" type="button" data-toggle="collapse" data-target="#navbarDropdown" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>

<div class="collapse navbar-collapse" id="navbarDropdown">
<ul class="navbar-nav mx-auto">
<li class="nav-item ">
<a class="nav-link " href="#" >Home</a>
</li>
<li class="nav-item ">
<a class="nav-link" href="#">Browse</a>
</li>
<li class="nav-item ">
<a class="nav-link" href="#">Search</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About</a>
</li>
</ul>
</div>
</nav>






</body>

</html>

关于html - bootstrap 4 navbar-toggler-icon(汉堡包)显示两行而不是三行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57476802/

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