【问题标题】:Bootstrap Hamburger icon not visibleBootstrap 汉堡图标不可见
【发布时间】:2021-02-04 07:34:56
【问题描述】:

我在 html/CSS 方面完全是新手,试图为应用程序制作一个简单的网页。有人可以告诉我为什么页面无法显示汉堡包图标。我认为它应该在品牌和开始文本之间显示为白色。这是使用以下脚本实际显示的屏幕截图。 截图:

/* Modify the background color */

.navbar-custom {
  background-color: #004d99;
}


/* change the brand and text color */

.navbar-custom .navbar-brand,
.navbar-custom .navbar-text {
  color: white;
}


/* change the link color */

.navbar-custom .navbar-nav .nav-link {
  color: white;
}


/* change the color of active or hovered links */

.navbar-custom .nav-item.active .nav-link,
.navbar-custom .nav-item:hover .nav-link {
  color: white;
}
<head>
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">

</head>
<nav class="navbar navbar-custom">
  <div>
    <a class="navbar-brand" href="/"><strong>The Brand</strong></a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation" style="color: white">
           <span class="navbar-toggler-icon" style="color: white"></span><small><strong> START</strong></small>
         </button>
  </div>
  <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>

任何帮助表示赞赏。

【问题讨论】:

  • toggler 没有附加图标。您在跨度中的班级只是说有一个班级,但是当您签入开发工具时,您可以看到之前或之后没有图标。您可能需要自己添加一个图标。
  • 注意这种感觉就像你想要一个汉堡包/手风琴组合?
  • stackoverflow.com/q/26317679/125981 在这里可能对您有所帮助,但不是 100% 它是重复的

标签: html css bootstrap-4 navbar


【解决方案1】:

在span标签之间插入一个图标图像&lt;span class="navbar-toggler-icon" style="color: white"&gt;&lt;/span&gt;下面我尝试添加我自己的图标,但你可以插入你的

示例

.navbar-custom {
  background-color: #004d99;
}


/* change the brand and text color */

.navbar-custom .navbar-brand,
.navbar-custom .navbar-text {
  color: white;
}


/* change the link color */

.navbar-custom .navbar-nav .nav-link {
  color: white;
}


/* change the color of active or hovered links */

.navbar-custom .nav-item.active .nav-link,
.navbar-custom .nav-item:hover .nav-link {
  color: white;
}
<head>
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
  <style>

  </style>
</head>
<nav class="navbar navbar-custom">
  <div>
    <a class="navbar-brand" href="/"><strong>The Brand</strong></a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation" style="color: white">
      <span class="navbar-toggler-icon" style="color: white"><img src="https://placehold.it/25x25/fc5"></span><small><strong> START</strong></small>
    </button>
  </div>
</nav>

【讨论】:

    【解决方案2】:

    您看不到汉堡按钮的原因是引导程序硬编码图标作为特定导航栏配置的背景图像。例如有 .navbar-light 和 .navbar-dark 当您添加导航元素时,它们会根据导航栏方案设置样式,因此对汉堡包的切换器进行编码:

    .navbar-dark .navbar-toggler-icon {
        background-image: url(data:image/svg+xml;charset=utf8,%3Csvg viewBox='0 0 30 30' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath stroke='rgba(255, 255, 255, 0.5)' stroke-width='2' stroke-linecap='round' stroke-miterlimit='10' d='M4 7h22M4 15h22M4 23h22'/%3E%3C/svg%3E);
    }
    

    因此,一种使用您的代码进行此操作的方法:使用引导程序中的导航栏类来配置元素样式并使用自定义背景,请参阅示例,其中添加了我在此处所做的更改的 cmets:

    /* Modify the background color */
    
    /*changed class-name*/
    .bg-custom {
      background-color: #004d99;
    }
    
    
    /* change the brand and text color */
    
    .navbar-custom .navbar-brand,
    .navbar-custom .navbar-text {
      color: white;
    }
    
    
    /* change the link color */
    
    .navbar-custom .navbar-nav .nav-link {
      color: white;
    }
    
    
    /* change the color of active or hovered links */
    
    .navbar-custom .nav-item.active .nav-link,
    .navbar-custom .nav-item:hover .nav-link {
      color: white;
    }
    <head>
      <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
    
    </head>
    <!--changed navbar-class to basic bootstrap class-->
    <nav class="navbar navbar-dark bg-custom">
      <div>
        <a class="navbar-brand" href="/"><strong>The Brand</strong></a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation" style="color: white">
               <span class="navbar-toggler-icon" style="color: white"></span><small><strong> START</strong></small>
             </button>
      </div>
      <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
      <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
      <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>

    或者您必须将自己的自定义图标添加到切换器。

    【讨论】:

    • 感谢您的支持,这个回答对我有进一步的帮助!
    猜你喜欢
    • 1970-01-01
    • 2018-08-05
    • 1970-01-01
    • 1970-01-01
    • 2021-04-29
    • 1970-01-01
    • 2018-12-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多