简体   繁体   中英

how to add menu to toggle navigation bar in bootstrap

So here's what I want to do, add login/signup(when logged out) add profile/logout(when logged in) in toggle navigation menu when my web is in mobile version(xs). I don't want anything when my web is in desktop version(sm,md, lg, xl)

I have code like this right now

<nav class="navbar navbar-default navbar-static-top" role="navigation">
  <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="{% url 'index' %}">MyWeb</a>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">


      </ul>

I need to add

  {% if user.is_authenticated %}
<a href="{% url 'userena_profile_detail' user.username %}" style="color:white">profile<i class="fa fa-user"></i></a></li>
    <li><a href="/accounts/signout" style="position:relative; right:15px; color:white">else</a>
{% else %}
    <li><a href="/accounts/signup/"style="color:white">signin<i class="fa fa-registered"></i></a></li>
    <li><a href="/accounts/signin/" style="position:relative; right:15px; color:white">login<i class="fa fa-sign-in"></i></a></li>

    {% endif %}

how do I do this? I don't want anything when it's in desktop version, I just want to simply put these when it's in xs and I get toggle nav menu

Try this :

<nav class="navbar navbar-default visible-xs-block">

Also, for your reference you can find other option from Bootstrap viewport breakpoints

Hope it helps :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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