Bootstrap导航项目未在移动设备上显示

时间:2018-01-10 11:42:24

标签: html css twitter-bootstrap

我目前正在使用bootstrap处理一些小事。这里我有一个导航栏。对于导航项"登录"和"退出"我已将其设置为使用justify-content-end保持在右侧。在大屏幕设备上,它是我想要的。但是,当我使用移动设备打开它时,导航栏会按照其意图折叠,但justify-content-end的项目不会显示。

有什么想法吗? 谢谢

  <nav class="navbar navbar-expand-lg navbar-dark bg-primary">
  <a class="navbar-brand" href="#">Jatitree</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <div class="collapse navbar-collapse" id="navbarNavAltMarkup">
    <div class="navbar-nav">
      <a class="nav-item nav-link" id="home" href="<?php echo base_url();?>">Home <span class="sr-only">(current)</span></a>
      <a class="nav-item nav-link" href="<?php echo base_url();?>BuyCars">Buy Goods</a>
      <a class="nav-item nav-link" href="<?php echo base_url();?>SellGoods">Sell Goods</a>
    </div>
  </div>

  <div class="collapse navbar-collapse justify-content-end" id="navbarNavAltMarkup">
    <ul class="navbar-nav">
      <li class="nav-item"</li>
        <?php
          if (!$this->session->userdata('logged_in'))
            echo '<a class="nav-link" href="'.base_url().'/Login">Login</a>';
            else echo '<a class="nav-link" href="#">Logout</a>';
        ?>
    </ul>
  </div>
</nav>

on large device

on small device/ mobile

1 个答案:

答案 0 :(得分:1)

HTML格式不正确(应该在li里面,而li缺少结束括号)。但是,问题是你已经命名了两个具有相同id但不起作用的元素。只需使用类名(即:navbar-alt)切换collapse个导航栏,并在data-target中定位此类。

https://www.codeply.com/go/BaZHtvCoAR

<nav class="navbar navbar-expand-lg navbar-dark bg-primary">
    <a class="navbar-brand" href="#">Jatitree</a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-alt" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse navbar-alt" id="navbarNavAltMarkup">
        <div class="navbar-nav">
            <a class="nav-item nav-link" id="home" href="&lt;?php echo base_url();?&gt;">Home <span class="sr-only">(current)</span></a>
            <a class="nav-item nav-link" href="&lt;?php echo base_url();?&gt;BuyCars">Buy Goods</a>
            <a class="nav-item nav-link" href="&lt;?php echo base_url();?&gt;SellGoods">Sell Goods</a>
        </div>
    </div>
    <div class="collapse navbar-collapse justify-content-end navbar-alt">
        <ul class="navbar-nav">
            <li class="nav-item nav-link">
                Logout
            </li>
        </ul>
    </div>
</nav>