How to move navbar items at the right [duplicate] - html

This question already has answers here:
Bootstrap align navbar items to the right
(24 answers)
Closed 3 years ago.
I'm using bootstrap classes and I need the logo to be in the left but nav items at the right.
To be responsive as well.
https://imgur.com/zL8LrTG
navbar now
<!-- Logo -->
<a class="navbar-brand" href="#">
<img class="img-fluid" src="images/header-logo.png" alt="logo">
</a>
<!-- Toggler/collapsibe Button -->
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsibleNavbar">
<span class="navbar-toggler-icon"></span>
</button>
<!-- Nav items -->
<div class="collapse navbar-collapse" id="collapsibleNavbar"> <!-- Collapse navbar -->
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Products</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Services</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Contact</a>
</li>
</ul>
</div>
</nav>

You can add ml-auto to your ul class, which gives your ul a margin-left of auto. It will look like this:
<ul class="navbar-nav ml-auto">

You can use float right to move nav bar right side
#collapsibleNavbar{
float: right;
margin: 0 10px 0 0;
}

You can try this:
// CSS code
nav #collapsibleNavbar{
width: n%; // n = o que achar melhor
margin: n n;
display: block;
}
nav #collapsibleNavbar .navbar-nav{
display: block;
width: auto; // or what You think is better for your project
margin: n n;
float: right;
}
I think you can try that and to encapsulate in a div your Logo and Toggler/collapsibe Button, setting div to float left. Maybe you'll need add some "!important".

Related

What css must I apply to get rid of this useless spacing?

I have a navbar that has some items, 4 of them to the left and one that must always be in the right. The thing is when I introduced the last one to the left, they got one word on top of the other and it looks awful. And one more thing is that when I change the resolution of the monitor, the item that's always on the right moves to the left almost touching the middle.
Some additional info would be that this is part of a project consisting in a web platform for colleges. It is mainly created with SpringBoot and its libraries, fully Java written in backend. Nonetheless, the frontend is mostly HTML, some CSS when I need to make it not look ugly and Javascript in case of animatios of effects. Also not to mention Thymeleaf framework so I can communicate with the backend properly.
I tried many things but I have no idea how to make them look nice. Someone willing to help me on this stylish matter?
I will add two pictures:
this one is when I have my browser put on the 24inch screen
this one is when I have my browser put on the 15.6inch screen of the laptop
And the code below is from the page:
#personal-page {
padding-left: 780px;
font-size: 20px;
}
#admin-page {
padding-left: 730px;
font-size: 20px;
}
#assistant-page {
padding-left: 700px;
font-size: 20px;
}
<html>
<head>
<nav class="fixed-top navbar navbar-dark bg-dark navbar-expand">
<a class="navbar-brand" href="https://curs.upb.ro/">
<span class="fa fa-university"></span> E-Learning Platform
</a>
<button class="navbar-toggler" 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" id="navi">
<li class="nav-item active">
<a class="nav-link" href="/">Homepage<span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" aria-current="page" href="/menu">Menu Page</a>
</li>
<li class="nav-item">
<a class="nav-link" aria-current="page" href="/admin/students">Students List</a>
</li>
<li class="nav-item">
<a class="nav-link" aria-current="page" href="/admin/camine">Camine Page</a>
</li>
<div th:switch="${isDevAcc}">
<li th:case="'true'" class="nav-item">
<div th:switch="${loggedUsername}">
<a th:case="'iancu'" id="admin-page" class="nav-link fas fa-code" aria-current="page" href="/admin/devAdminPage">
<span> Dev Account :: ADMIN </span>
</a>
<a th:case="'lixi'" id="assistant-page" class="nav-link fas fa-code" aria-current="page" href="/admin/devAdminPage">
<span> Dev Account :: ASISTENT </span>
</a>
</div>
</li>
<li th:case="'false'" class="nav-item" id="personal-page">
<a class="nav-link fas fa-user-secret" aria-current="page" href="#" th:text="${loggedUsername}"></a>
</li>
</div>
</ul>
</div>
</nav>
</head>
<body>
</body>
</html>
Use flexbox to align your navbar horizontally: nav ul { display: flex; }
Then you also can use the :last-child selector to apply margin-left: auto; which will push the last item to the right: nav ul li:last-child { margin-left: auto; }. margin: auto; within a flex-container will consume all remaining space.
nav ul {
display: flex;
}
nav ul li:last-child {
margin-left: auto;
}
/* For styling purpose only */
nav ul {
list-style: none;
padding: 5px;
}
nav li {
margin: 0 10px;
}
<nav>
<ul>
<li>E-Learning Plattform</li>
<li>Homepage</li>
<li>Menu Page</li>
<li>Students List</li>
<li>Camine Page</li>
<li>Admin</li>
</ul>
</nav>

Keep navbar menu on center when adding a navbar brand

I'm having problems keeping the menu items on center when I'm adding a navbar brand.
The menu items move slightly to the right when I'm adding a logo on the left side of the navbar?
How to keep it centered?
Here is my navbar code(bootstrap):
<div class="collapse navbar-collapse" id="navbarTogglerDemo01">
<a class="navbar-brand" href="#"><img class="img-fluid" src="https://psmedia.playstation.com/is/image/psmedia/call-of-duty-warzone-badge-01-ps4-en-27feb20_1583405365530?$HugeHero_Badge$" height="15%" width="15%"></a>
<ul class="navbar-nav mx-md-auto mt-2 mt-lg-0">
<li class="nav-item active">
<a class="nav-link" href="#">WEAPONS <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">LOADOUTS</a>
</li>
</ul>
TEST
</div>
</nav>
With the code you provided here is a quick workaround. It may not be the most organized solution but it should work.
You can also remove the default padding in li tags. That causes things to move a little to the right.
Your Styles.css
/* Set all contents in container to be centered automatically */
#navbarTogglerDemo01 {
position: absolute;
top: 0px;
left: 0px;
width: 100vw;
max-width: 100vw;
display: block;
text-align: center;
}
/* And all direct sub tags display inline block */
.navbar-brand .navbar-nav .button {
display: inline-block;
}
ul {
list-style-type: none;
padding: 0;
}
<div class="collapse navbar-collapse" id="navbarTogglerDemo01">
<a class="navbar-brand" href="#"><img class="img-fluid" src="https://images.pexels.com/photos/176837/pexels-photo-176837.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=2" height="15%" width="15%"></a>
<ul class="navbar-nav mx-md-auto mt-2 mt-lg-0">
<li class="nav-item active">
<a class="nav-link" href="#">WEAPONS <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">LOADOUTS</a>
</li>
</ul>
TEST
</div>
</nav>
Another quick solution, but not 100% responsive:
/* This will move each block slightly back to the left, remember to provide a unit to move left. */
.navbar-brand,
.navbar-nav {
position: relative;
left: -10px;
/* Change this to your custom amount: px % em ... etc */
}
<nav>
<div class="collapse navbar-collapse" id="navbarTogglerDemo01">
<a class="navbar-brand" href="#">
<img class="img-fluid" src="https://images.pexels.com/photos/176837/pexels-photo-176837.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=2" height="15%" width="15%">
</a>
<ul class="navbar-nav mx-md-auto mt-2 mt-lg-0">
<li class="nav-item active">
<a class="nav-link" href="#">WEAPONS <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">LOADOUTS</a>
</li>
</ul>
TEST
</div>
</nav>
Please let me know if this helps or in case you have a question.
Good Luck!!

Bootstrap 4 navbar menu (mobile) style like in Bootstrap 3? [duplicate]

This question already has answers here:
Bootstrap 4 responsive navbar vertical
(2 answers)
Closed 6 years ago.
Bootstrap 4 example
Bootstrap 3 example
How to get Bootstrap 4 menu like in Bootstrap 3?
This code from bootstrap 4 http://v4-alpha.getbootstrap.com/examples/navbar/:
<div class="container">
<nav class="navbar navbar-light bg-faded">
<button class="navbar-toggler hidden-sm-up" type="button" data-toggle="collapse" data-target="#navbar-header" aria-controls="navbar-header">
☰
</button>
<div class="collapse navbar-toggleable-xs" id="navbar-header">
<a class="navbar-brand" href="#">Navbar</a>
<ul class="nav navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Features</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Pricing</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">About</a>
</li>
</ul>
<form class="form-inline pull-xs-right">
<input class="form-control" type="text" placeholder="Search">
<button class="btn btn-outline-success" type="submit">Search</button>
</form>
</div>
</nav> <!-- /navbar -->
</div><!-- /container -->
You need to add some css in bootstrap 4 and I imagine they are doing this because you can toggle the menu at different sizes so you need to add the media queries to whatever size you want your menu to open at. Something like so:
Here is a fiddle with some custom styles for the bootstrap 4 navbar Bootstrap 4 Navbar Fiddle
#media(max-width:33.9em) {
.navbar .collapse {max-height:250px;width:100%;overflow-y:auto;overflow-x:hidden;}
.navbar .navbar-brand {float:none;display: inline-block;}
.navbar .navbar-nav>.nav-item { float: none; margin-left: .1rem;}
.navbar .navbar-nav {float:none !important;}
.nav-item{width:100%;text-align:left;}
.navbar .collapse .dropdown-menu {
position: relative;
float: none;
background:none;
border:none;
}
}

Fix the height of my Sign in button in my navbar

I've followed this post accepted answer to vertical align my navbar links with my logo.
But my SignIn link also follow the vertical size and span to the full 50px of the navbar height:
How can I set a normal height to my Sign In button?
Thanks.
HTML:
<!-- /navbar -->
<nav class="navbar navbar-static-top bg-faded">
<button class="navbar-toggler hidden-sm-up" type="button" data-toggle="collapse" data-target="#navbar-header"
aria-controls="navbar-header">
☰
</button>
<!-- Logo -->
<a class="navbar-brand" href="/en/">
<img class="img" height="50px" src="/static/images/logo.png"/>
</a>
<div class="collapse navbar-toggleable-xs" id="navbar-header">
<ul class="nav navbar-nav">
<!-- logged-in nav items -->
<!-- <a class="nav-item nav-link " href="/en/product/">Product</a> -->
<!-- <a class="nav-item nav-link " href="/en/pricing/">Pricing</a> -->
<!-- <a class="nav-item nav-link " href="/en/clients/">Clients</a> -->
<a class="nav-item nav-link " href="/en/about/">About Us</a>
</ul>
<!-- to designers: I am not sure about the 'float: right' style -->
<ul class="nav navbar-nav" style="float: right">
<!-- ... -->
<a class="nav-item btn btn-primary" href="/en/accounts/login/">Sign In</a>
</ul>
</div>
</nav>
And CSS:
.navbar {
background-color: white;
border-bottom-color: lightgray;
border-bottom-style: solid;
border-bottom-width: thin;
}
.nav-item {
line-height: 50px;
}
You are applying the CSS class nav-item which sets line-height: 50px to "Sign in" button. Simply remove it like so:
<a class="btn btn-primary" href="/en/accounts/login/">Sign In</a>
That will make the button height normal. But you ll still have to add something like a top margin to vertically align the button with other links and logo.
.navbar-nav .btn {
margin-top: 10px; // Adjust the actual number of pixels accordingly
}
However you HTML code is also no quite valid. If the hackish code was not intentional you should refer Bootstrap Docs to correctly apply their HTML structures and CSS classes.

Why is my bootstrap navbar not displaying inline?

Here is my html using bootstrap (I'm sure bootstrap is installed correctly)
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand">Rebar</a>
</div>
<div>
<ul class="nav navbar-nav">
<li>Link</li>
<li>Link</li>
<li>Link</li>
</ul>
</div>
</div>
</nav>
When it displays the three links are being displayed as block elements.
This is because in Bootstrap the css for li is this:
.nav>li {
position: relative;
display: block;
}
But for me the menu seems to appear correctly. See snippet, but only on a full page. On mobile devices it will behave like a block element since the screen doesn't have room to show them inline.
EDIT: Updated the snippit to work as requested (see comments below this answer)
.navbar .container-fluid>.navbar-header {
float: left;
margin-right: 10px;
}
.navbar .navbar-nav {
float: left;
margin: 5px;
}
.nav>li {
float: left;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand">Rebar</a>
</div>
<div style="display: inline-block;">
<ul class="nav navbar-nav">
<li>Link
</li>
<li>Link
</li>
<li>Link
</li>
</ul>
</div>
</div>
</nav>
Currently on Bootstrap 4. The flex layout seems to be columnar by default in my ecosystem as well.
The most direct override for this use case:
.navbar-nav {
flex-direction: row;
}
Just ran into this issue with BS4. Learned I needed to add navbar-expand-lg class to my nav.
<nav class="navbar navbar-expand-lg">
I'm not saying the other answers are incorrect in any way, but all that is really needed to accomplish the original question is this entry in the subtheme's CSS file:
.nav.navbar-nav li {
float: left;
}
It should be noted that the class(s) before the li will vary depending on selections in the Appearance section of the theme and other factors. For example, right out of the box the class would have been .menu.nav li
I was facing the same problem.
Try this:
.navbar-nav {
display: inline-block;
}
.navbar-nav>li {
display: inline-block;
}
It worked for me
If you want like this way check this DEMO
<nav class="navbar navbar-default navbar-static-top" id="topnavbar">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#top_navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div id="top_navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li>
Link 1
</li>
<li>
Link 2
</li>
<li>
Link 3
</li>
</ul>
</div>
</div>
</nav>
Currently on Bootstrap 4, the inline navbar can be achieved by adding class "nav-item" on list elements and class "nav-link" on a tags like this:
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand">Rebar</a>
</div>
<div>
<ul class="nav navbar-nav">
<li class="nav-item">
<a class= "nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class= "nav-link" href="#">Link</a>
</li>
<li class="nav-item">
<a class= "nav-link" href="#">Link</a>
</li>
</ul>
</div>
</div>
</nav>
Navbars require a wrapping .navbar with .navbar-expand{-sm|-md|-lg|-xl} for responsive collapsing and color scheme classes.
So if your nav class is like that
change lg to sm or if -sm then change into -lg
You can make an inline navbar easily with this custom CSS class:
Css:
.nav.inline-navbar>li{
display: inline-block;
}
Now use it in your Html:
.....
<ul class="nav navbar-nav inline-navbar">
......
</ul>
.....
For a quuick modify, I add style="display: inline" in the below position:
<div class="collapse navbar-collapse" id="navbarSupportContent" style="display: inline">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="#" onclick="toggleContent('single')">One Line Param</a>
</li>
<li class="nav-item active">
<a class="nav-link" href="#" onclick="toggleContent('multi')">Multi Line Param</a>
</li>
</ul>
</div>
just simply add this into your CSS and get the elements in one line
.navbar-nav {
display: inline-block;
}
.navbar-nav li {
display: inline-block;
}
In the snippet below, the highlighted line used to be <div class="nav navbar-nav">. In this case, just removing 'navbar-nav' solved the problem to me.
<nav class="navbar fixed-top" id="homehead">
<img class="navbar-brand" src="" height=50 width=50 alt="">
THIS LINE-> <div class="nav">
<a class="nav-item nav-link" href="">Link1<span
class="sr-only"></span></a>
<a class="nav-item nav-link" href="">Link2</a>
<a class="nav-item nav-link" href="">Link3</a>
<a class="nav-item nav-link" href="">Link4</a>
</div>