I have a Bootstrap Navbar that has lot of tabs. The Bootstrap Nav Bar looks like this.
Is there any way to prevent it.
The HTML Code:
<link rel="stylesheet" href="CDNs/bootstrap.css">
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">v1.0</a>
</div>
<ul class="nav navbar-nav">
<li style="float:right">Upload</li>
<li style="float:right">Events of ©</li>
<li style="float:right">Tracker</li>
<li style="float:right"><span class="glyphicon glyphicon-pencil"></span> Return</li>
<li style="float:right"><a href="#"><span class="glyphicon glyphicon-inbox"></span> My< /a></li>
<li style="float:right"><span class="glyphicon glyphicon-user"></span> SignOut</li>
<li style="float:right"><a class="navbar-brand" href="#"><?php
echo "Logged in as " . $_SESSION["username"] . "<br>";
?></a></li>
</ul>
</div>
</nav>
*I have masked few tab names and edited the tab names in the code due to security issues*
Thanks,
If what you need is to have them all in one line, this fiddle should work.
These were the only properties needed:
.nav.navbar-nav {
display: inline-block;
float: right;
}
ul.nav.navbar-nav > li {
display: inline-block;
}
Here is the image:
You can see all tabs are in order (the signOut tab looks like that because it has an anchor tag on top of it).
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
There are few mistakes in your markup
1) There is an extra space on your closing < /a> tag in your "My" option
<li style="float:right"><a href="#"><span class="glyphicon glyphicon-inbox"></span> My< /a></li>
Remove this.
2) Next remove all your inline style (float:right;). If you want to shift all towards right then just add the class navbar-right to your <ul> like this
<ul class="nav navbar-nav navbar-right">
<li></li>
<li></li>
<li></li>
</ul>
Codepen here
Related
I cannot find out why the dropdown menu does not work. I am completely new in web dev
enter image description here
Make sure you have added bootstrap CDN link like:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
Check this link for navbar with dropdown menu:
https://www.w3schools.com/bootstrap4/tryit.asp?filename=trybs_navbar_dropdown&stacked=h
Post your html and css here. I can see only html code in image
Make the dropdown-menu class div tag a ul tag and all the links that need to be dropdown-items in li tags. That should work I guess.
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Categories
<span class="caret"></span></a>
<ul class="dropdown-menu">
<li class="dropdown-item">Item 1</li>
<li class="dropdown-item">Item 2</li>
<li class="dropdown-item">Item 3</li>
</ul>
</li>
Thanks for checking out my post. First time reaching out for help.
My problem is I can't seem to center the elements within my nav no matter what I try.
Here's what my code is putting out.
Here's what I'd like it to do.
So basically, I'd like to center the content in the middle col-sm-8 & the col-sm-2 on the right side of the page as well.
Here's my HTML.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS-->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!-- Bootstrap jquery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Bootstrap Javascript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<!-- My CSS -->
<link rel="stylesheet" type="text/css" href="css/main.css">
<title>Working Title</title>
</head>
<body>
<!-- The Navbar & row-->
<nav class="navbar navbar-inverse row">
<div class="container-fluid">
<!-- The logo Img. -->
<div class="col-sm-2 L-sm-2">
<div class="navbar-header">
<a class="navbar-brand" href="#"><img src="Img/logo.jpg" style=""></a>
</div>
</div>
<!-- Begin Page Links. This can change the text size also. -->
<ul class="nav navbar-nav col-sm-8 PageLinks">
<!-- Play! -->
<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#">Play! <span class="caret"></span></a>
<ul class="dropdown-menu">
<li>PvE</li>
<li>PvP</li>
</ul>
</li>
<!-- About -->
<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#">About <span class="caret"></span></a>
<ul class="dropdown-menu">
<li>The Game</li>
<li>Development</li>
<li>Monster Manual</li>
</ul>
</li>
<!-- Forum -->
<li>Forum</li>
<!-- Statistics -->
<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#">Statistics <span class="caret"></span></a>
<ul class="dropdown-menu">
<li>General</li>
<li>PvE</li>
<li>PvP</li>
</ul>
</li>
<!-- Armory -->
<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#">Armory <span class="caret"></span></a>
<ul class="dropdown-menu">
<li>PC Armory</li>
<li>PC Builder</li>
</ul>
</li>
<!-- Help! -->
<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#">Help <span class="caret"></span></a>
<ul class="dropdown-menu">
<li>FAQ</li>
<li>Contact</li>
</ul>
</li>
</ul>
<!-- The sign up / sign in stuff. -->
<div class="nav navbar-nav navbar-right R-sm-2 col-sm-2">
<ul class="">
<li><span class="glyphicon glyphicon-log-in"></span> Login</li><br>
<li><span class="glyphicon glyphicon-user"></span> Sign Up</li>
</ul>
</div>
</div>
</nav>
Here's my CSS
* {
/* Makes sure that the padding and border are included in the total width and height of the elements in the Grid. */
box-sizing: border-box;
}
/* Setting the heignt for the logo in the nav bar. */
nav a img {
max-height: 100px;
width: auto;
}
/* Setting the height for the columns in the nav. */
nav .col-sm-2, .col-sm-8{
height: 140px;
}
/* Setting the navbar height & the opacity */
.navbar{
height: 140px;
opacity: .9;
}
/* Setting the left border for the Sign up / Sign in area. */
.R-sm-2{
border-left: 2px solid white;
line-height: 3.3;
}
/* Setting the left border for the Sign up / Sign in area. */
.L-sm-2{
border-right: 2px solid white;
}
.PageLinks{
}
I appreciate any help!
I would change your nav tag to a div tag like this:
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<a href="#Url.Action("Index", "Home")">
I found the solution myself using Flexbox. I'm posting it here for anyone who might find this in the future with the same problem.
All I did was add this to my CSS above.
.PageLinks{
/* Makes the text larger */
font-size: 2.7em;
/* Sets the container to flex */
display: flex;
/* Centers the content horizontally */
justify-content: center;
/* Centers the content vertically */
align-items: center;
}
I used bootstrap and I would like to change the active page background to green but it doesn't work.
.navbar-inverse {
color: #fff;
background-color: #4CAF50;
}
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<div class="logo">
<img src="images/logo.png">
</div>
</div>
<ul class="nav navbar-nav">
<li class="active">Home</li>
<li>About</li>
<li>Contact</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><span class="glyphicon glyphicon-log-in"></span> Logout</li>
</ul>
</div>
</nav>
When I change the background-color in "Inspect Element" it works like a charm. I don't know what to try anymore.
Thanks!
I tested your code on my computer and it works perfectly.
Why it's not working for you is, I'm guessing, because you are linking your CSS before Bootstrap in HTML. In order to override Bootstrap's CSS, you need to link your custom CSS after Bootstrap.
Eg:
<link href="bootstrap.css" ...>
<!-- put your custom css after bootstrap -->
<link href="my-custom-style.css" ...>
I'm new to bootstrap and in my application I want to have a navbar at the top of the page. The navbar should contain the brand name and then to the right of it it should have some options. But whenever I use navbar-right it doesn't work and the page I get looks like this
As you can see everything is squashed together with the brand name on the left hand side. What I have tried to fix this is by using pull-right which does work perfectly but I want to know why navbar-right isn't.
homeTemplate.html
<body>
<nav class="navbar navbar-default">
<div class="navbar-inner">
<div class="container-fluid">
<div class="navbar-header">
MyApp
</div>
<ul class="nav navbar-nav navbar-right">
<li>Profile</li>
<li>Notifications</li>
<li>Messages</li>
<li>Options</li>
</ul>
</div>
</div>
</nav>
</body>
I think you might have missed some library.
See the given below snippet I have added
Jquery library
bootstrap.js and
bootstrap.css
Its working fine. see the below snippet
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<nav class="navbar navbar-default">
<div class="navbar-inner">
<div class="container-fluid">
<div class="navbar-header">
MyApp
</div>
<ul class="nav navbar-nav navbar-right">
<li>Profile</li>
<li>Notifications</li>
<li>Messages</li>
<li>Options</li>
</ul>
</div>
</div>
</nav>
There might be a version issue. For Bootstrap version 4, Use <ul class="nav navbar-nav ml-auto"> for moving element to the right.
Try using two Unordered-Lists, one for the nav-brand and the elements you require to be aligned left and then use separate unordered-lists with the "nav navbar-nav navbar-right" class to get the right aligned elements. Check the snippet below.
<nav class="navbar navbar-default navbar-static-top">
<div class="topnav">
<ul class = "nav navbar-nav">
<li><a class="navbar-brand bigbrand" href="{% url 'urls' %}">BRAND name</a></li>
<li><a class="navbar-link" href="{% url 'urls' %}">Home</a></li>
<li><a class = "navbar-link" href="urls">News</a></li>
<li><a class = "navbar-link" href="urls">Contact</a></li>
<li><a class = "navbar-link" href="{% url 'urls' %}">test</a></li>
</ul>
<ul class = "nav navbar-nav navbar-right">
<li>logout</li>
</ul>
</div>
</nav>
I'm testing the bootstrap navbar and how I do not know much about styles. When I click the icon, a dotted frame appears outside the image boundary, as follows:
image result
I know this is related to the page style, but do not know how to solve. Below is the exact code I'm using:
<!DOCTYPE html>
<html>
<head>
<link href="css/bootstrap.css" rel="stylesheet">
<link href="font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
</head>
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="#">
<img alt="Brand" src="lib/img/mig.png">
</a>
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
</button>
<h1 class="navbar-header" href="#">Home</h1>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-navbar-collapse-1">
<br>
<ul class="nav nav-pills navbar-right">
<li class="active">
Home
</li>
<li class="">
About
</li>
<li class="">
Contact
</li>
<li class="">
Maps
</li>
</ul>
</br>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
<body>
</body>
</html>
This wheel is standard browsers to "links"
To resolve you have two options
- Include it in your tag
a: active {
outline: none;
}
Include a height with the same height as your image
.navbar-brand {
height: 60px;
}
Helped?
Try to add this rule in your css file
a {
outline: none;
}
source: css tricks
The first posted answer may solve the problem, but it would also affect every anchor tag on the page, which seems a bit overkill.
I'd suggest this instead:
.navbar .navbar-brand:focus {
outline: none;
}