Currently, my navbar in bootstrap looks fine when in full screen. It looks like this.
However, bootstrap automatically condense the items in to a stack when below a certain width. That is when it looks bad as the Register and Login are on the same line. Looks like this.
I want the navbar to have the Register and Login routes on the right while containing the routes as a stack when condensed.
Current HTML for the nav.
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<nav >
<div >
<a href="{{ url_for('home')}}">Test</a>
<button type="button" data-bs-toggle="collapse" data-bs-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
<span ></span>
</button>
<div id="navbarText">
<ul >
<li >
<a aria-current="page" href="#">Home</a>
</li>
<li >
<a href="#">Features</a>
</li>
<li >
<a href="#">Pricing</a>
</li>
</ul>
{% if current_user.is_authenticated %}
<span >
<a href="{{ url_for('logout')}}" >Logout</a>
</span>
{% else%}
<span >
<a href="{{ url_for('login')}}" >Login</a>
</span>
<span >
<a href="{{ url_for('register')}}" >Register</a>
</span>
{% endif %}
</div>
</div>
</nav>
CodePudding user response:
Navbar should appear as a stack only in mobile view. You can also consider checking if you have added xs- classes properly to get the desired view. I can only see lg classes in your snippet. Pelase try to share the codepen if it still doesn't work.
CodePudding user response:
Well, I am not sure if I understand the question pretty well, but from what I understand I would move the login, register, and logoff into a div and apply a media query in the CSS to do what you ask for.
<style>
@media only screen and (max-width: 990px) {
.chnageMeWhenSmall {
position: absolute;
right: 60px;
}
}
</style>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<nav >
<div >
<a href="{{ url_for('home')}}">Test</a>
<button type="button" data-bs-toggle="collapse" data-bs-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
<span ></span>
</button>
<div id="navbarText">
<ul >
<li >
<a aria-current="page" href="#">Home</a>
</li>
<li >
<a href="#">Features</a>
</li>
<li >
<a href="#">Pricing</a>
</li>
</ul>
<div >
{% if current_user.is_authenticated %}
<span >
<a href="{{ url_for('logout')}}" >Logout</a>
</span>
{% else%}
<span >
<a href="{{ url_for('login')}}" >Login</a>
</span>
<span >
<a href="{{ url_for('register')}}" >Register</a>
</span>
{% endif %}
</div>
</div>
</div>
</nav>