简体   繁体   English

引导程序:导航栏图标在手机上不可见

[英]Bootstrap: Navbar toggler icon not visible with mobile phone

I am working on my web application using Bootstrap v4. 我正在使用Bootstrap v4开发Web应用程序。 For the navigation I'm using the navbar toggler and everything is working fine on my desktop (Firefox). 对于导航,我使用导航栏切换器,并且在桌面(Firefox)上一切正常。 However, when I browse the same website with my mobile phone, on both Google Chrome and Firefox Focus the toggler icon is not visible. 但是,当我用手机浏览相同的网站时,在Google Chrome和Firefox Focus上都看不到切换开关图标。 I do not know why is that. 我不知道为什么。

Here my code snippet: 这是我的代码段:

 .navbar-toggler { color: rgba(0,0,0,.5); border-color: rgba(0,0,0,.1); } .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(0, 0, 0, 0.5)' stroke-width='2' stroke-linecap='round' stroke-miterlimit='10' d='M4 7h22M4 15h22M4 23h22'/%3E%3C/svg%3E"); } 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet"/> <nav class="navbar navbar-expand-sm mb-3"> <button class="navbar-toggler btn-block" type="button" data-toggle="collapse" data-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"> <ul class="navbar-nav mr-auto justify-content-end w-100"> # the links </ul> </div> </nav> 

Because of the .collapse class you're using, .collapse class look like this: 由于您使用的是.collapse类,因此.collapse类如下所示:

.collapse {
    display: none;
    visibility: hidden;
}

@media (min-width: 768px)
.navbar-collapse.collapse {
    display: block!important;
    height: auto!important;
    padding-bottom: 0;
    overflow: visible!important;
    visibility: visible!important;
}

Your Code is perfect, Please Add Sequence wise css and jquery like this 您的代码是完美的,请像这样添加Sequence明智的CSS和jquery

<meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>

I had the same problem. 我有同样的问题。 Scripts loaded in correct order, two slightly different pages, one pure html, the other a dynamic django page. 脚本以正确的顺序加载,两个略有不同的页面,一个是纯html,另一个是动态django页面。 Button showed fine on the static page, but on the dynamic page, when changing to mobile size, the button showed as a blank square, instead of a square with lines. 按钮在静态页面上显示正常,但是在动态页面上,当更改为移动大小时,按钮显示为空白正方形,而不是带有线条的正方形。 I tried many different things, script order, checked tags were correctly terminated, shook my magic dice while wearing a moose head. 我尝试了许多不同的事情,脚本顺序,检查的标签是否正确终止,戴着麋鹿头摇了摇我的魔术骰子。 Then I changed my icon for the button from 然后我将按钮的图标从

    <nav class="navbar navbar-expand-lg navbar-light bg-light">
      <a class="navbar-brand" href="#">Working: Job List</a>
      <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navmobile" 
                     aria-controls="navmobile" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
      </button>

to

<nav class="navbar navbar-expand-lg navbar-light bg-light">
    <a class="navbar-brand" href="#">Working: Job List</a>
      <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navmobile" 
                     aria-controls="navmobile" aria-expanded="false" aria-label="Toggle navigation">
        <i title="" class="fa fa-bars"></i>
      </button>

so just changing the icon to a fontawesome one for the button in the last line, and the button showed. 因此只需将最后一行中的按钮的图标更改为惊人的图标,按钮就会显示出来。 Go figure.... 去搞清楚....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM