本文介绍了如何在Bootstrap 4中隐藏和替换navbar-toggler-icon?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何隐藏和替换Bootstrap 4中的navbar-toggler-icon?现在,下面的代码只是将'X'放在汉堡菜单下面。

How do you hide and replace the navbar-toggler-icon in Bootstrap 4? Right now the code below just puts the 'X' below the hamburger menu.

<nav class="navbar navbar-toggleable-md">
  <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" 
  data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" 
  aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>

  <div class="collapse navbar-collapse" id="navbarsExampleDefault">

     <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" 
  data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" 
  aria-label="Toggle navigation">
    <span>X</span>
  </button>
</nav>


推荐答案

你现在拥有的代码有2个togglers,但我我不确定为什么。您只需要用X替换普通的 navbar-toggler-icon

The code you have now has 2 togglers, but I'm not sure why. You just need to replace the normal navbar-toggler-icon with an X..

<nav class="navbar navbar-faded navbar-toggleable-md">
    <button class="navbar-toggler navbar-toggler-right py-2" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
       <span>X</span>
    </button>
    <a href="" class="navbar-brand">Brand</a>
    <div class="collapse navbar-collapse" id="navbarsExampleDefault">
        <ul class="navbar-nav">
            <li><a href="">Link</a></li>
        </ul>
    </div>
</nav>

编辑要在汉堡包切换器图标和关闭X之间切换,我需要在 navbar-toggler 中同时拥有X和汉堡包图标。添加一些CSS来处理导航栏的折叠状态。

EDIT To toggle between the hamburger toggler icon and a close X, you'd need have both the X and hamburger icon inside the navbar-toggler. Add some CSS to handle the collapsed state of the navbar.

.navbar-toggler>.close {
    display:inline;
}
.navbar-toggler.collapsed>.close, .navbar-toggler:not(.collapsed)>.navbar-toggler-icon {
    display:none;
}

这篇关于如何在Bootstrap 4中隐藏和替换navbar-toggler-icon?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 10:10