我正在使用引导程序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>

09-18 01:34