I am developing a small app and have now to deal with the front end part of it. I am using bootstrap for it. For the navbar part, I am using nav-pills navbar, and I want it stretched to 100%. My navbar code:
<div class="navbar navbar-static-top" >
<div class="navbar-inner">
<ul class="nav nav-pills" >
<li >Home</li>
<li>Some</li>
<li>Items</li>
<li>Here</li>
<li>Register</li>
<li>Login</li>
</ul>
</div>
</div>
Now the css part:
.nav-pills{
margin-top:20px;
width:100%;
}
.nav-pills > li {
float: left;
}
Now if i change the 100% in nav-pills to say 1366px, it works. But when I scale it to 100%, the navbar is not stretched. I tried giving the width of .nav-pills > li to 25%, trying with just 4 tabs. That also gives the perfect result. But since the number of tabs vary from page to page, I don't want to fix the size of the .nav-pills > li class. I want to stretch the navbar to full width. What is that I should do?
Bootstrap 3 has a nav-justified class that does exactly what you want (at screens wider than 768px, on smaller screens the nav links are stacked).
Just add it to your .nav like this:
<ul class="nav nav-pills nav-justified">
<li >Home</li>
<li>Some</li>
<li>Items</li>
<li>Here</li>
<li>Register</li>
<li>Login</li>
</ul>
Demo fiddle
nav-pills nav-justified items not width fixed.
For this case:
HTML
<div class="gridProducts_box">
<ul class="nav nav-pill">
<li class="gridProducts_box__items">
One
</li>
<li class="gridProducts_box__items">
Two
</li>
<li class="gridProducts_box__items">
Three
</li>
<li class="gridProducts_box__items">
Four
</li>
<li class="gridProducts_box__items">
Five
</li>
</ul>
</div>
CSS
/* nav tabs fixed wodth */
.gridProducts_box > ul.nav.nav-pills {
display: table;
width: 100%;
table-layout: fixed;
}
.gridProducts_box > ul.nav.nav-pills > li {
float: none;
display: table-cell;
}
.gridProducts_box > ul.nav.nav-pills > li > a {
text-align: center;
}
.gridProducts_box__items {
width: 100%;
}
Demo
Related
You can see that the icon and "sign in" link isn't straight. How do I fix this?
Here is the code:
https://html-css-js.com/?html=%3C!DOCTYPE%20html%3E%0A%3Chtml%20lang=%22en%22%3E%0A%20%20%3Chead%3E%0A%20%20%20%20%3Cmeta%20charset=%22UTF-8%22%20/%3E%0A%20%20%20%20%3Cmeta%20http-equiv=%22X-UA-Compatible%22%20content=%22IE=edge%22%20/%3E%0A%20%20%20%20%3Cmeta%20name=%22viewport%22%20content=%22wi$*$dth=device-wi$*$dth,%20initial-scale=1.0%22%20/%3E%0A%20%20%20%20%3Clink%20rel=%22stylesheet%22%20href=%22styles.css%22%20/%3E%0A%20%20%20%20%3Clink%20rel=%22stylesheet%22%20href=%22https://fonts.googleapis.com/icon?family=Material+Icons%22%3E%0A%20%20%20%20%3Ctitle%3EGoogle%3C/title%3E%0A%20%20%3C/head%3E%0A%20%20%3Cbody%3E%0A%20%20%20%20%3C/ul%3E%0A%20%20%20%20%20%20%3Cli%20class=%22right%20button%22%3E%3Ca%20href=%22#%22%3ESign%20In%3C/a%3E%3C/li%3E%0A%20%20%20%20%20%20%3Cli%20class=%22right%22%3E%3Cspan%20class=%22material-icons%20navigation%20icon%22%20%3Eapps%3C/span%3E%3C/li%3E%0A%20%20%20%20%20%20%3Cli%20class=%22right%22%3E%3Ca%20href=%22#%22%3EImages%3C/a%3E%3C/li%3E%0A%20%20%20%20%20%20%3Cli%20class=%22right%22%3E%3Ca%20href=%22#%22%3EGmail%3C/a%3E%3C/li%3E%0A%20%20%20%20%20%20%3Cli%20class=%22left%22%3E%3Ca%20href=%22#%22%3EAbout%3C/a%3E%3C/li%3E%0A%20%20%20%20%20%20%3Cli%20class=%22left%22%3E%3Ca%20href=%22#%22%3EStore%3C/a%3E%3C/li%3E%0A%20%20%20%20%3C/ul%3E%0A%0A%20%20%3C/body%3E%0A%3C/html%3E%0A&css=*%20%7B%0A%20%20margin:%200;%0A%20%20padding:%200;%0A%20%20font-size:%2012px;%0A%20%20font-family:%20arial,%20sans-serif;%0A%7D%0A%0Ali%20%7B%0A%20%20float:%20right;%0A%20%20list-style-type:%20none;%0A%20%20margin-top:%2020px;%0A%7D%0A%0Aa%20%7B%0A%20%20text-decoration:%20none;%0A%20%20color:%20black;%0A%7D%0A%0A.left%20%7B%0A%20%20float:%20left;%0A%7D%0A%0A.left%20a%20%7B%0A%20%20margin-left:%2020px;%0A%7D%0A%0A.right%20%7B%0A%20%20margin-right:%2020px;%0A%7D%0A%0A.button%20%7B%0A%20%20background-color:%20#4485f4;%0A%20%20padding:%207px;%0A%20%20border-radius:%205%25;%0A%7D%0A%0A.button%20a%20%7B%0A%20%20color:%20#fff;%0A%7D%0A%0A.icon%20%7B%0A%20%20color:%20grey;%0A%7D%0A%0Aa%20%7B%0A%20%20justify-items:%20center;%0A%7D%0A&js=
In your css, you can write this in your ul selector:
ul {
display: flex;
align-items: center;
}
But in this case, rearrange your html code and write them in the order the options are going to be on your navbar.
<ul>
<li class="left">About</li>
<li class="left">Store</li>
<li class="right">Images</li>
<li class="right">Gmail</li>
<li class="right"><span class="material-icons navigation icon">apps</span</li>
<li class="right button">Sign In</li>
</ul>
Another way is to do that is to use line-height in ul.
ul {
line-height: 20px;
}
Although it is not always perfect.
Trying to use bootstrap to design a top navigation layout and I see that it defaults to left align. how do I get it to use full width of top?
Current
https://jsfiddle.net/v2notb5n/
<nav class="navbar">
<div class="fluid-container">
<ul class="nav navbar-nav navbar-inverse">
<li class="nav_page active"> Home </li>
<li class="dropdown"><a class="dropdown-toggle" data-toggle="dropdown" href="#" class="nav_txt"> Team <span class="caret"></span></a></li>
<ul class="dropdown-menu">
<li>National</li>
<li>Geo</li>
<li>Team Pictures</li>
</ul>
<li> About us </li>
</ul>
</div>
</nav>
Expected result:
https://imgur.com/a/ZQDR0
I tried something similar I found here Bootstrap navbar justify / span menu items occupying full width
but that didn't work for me.
Updated based on suggestions and answer here: https://jsfiddle.net/uahwra75/1/
To have the navbar stretch the full width, simply overwrite the float: left on .navbar-nav for medium screen widths and higher, with:
#media screen and (min-width: 768px) {
.navbar-nav {
float: none;
}
}
I've created a working fiddle showcasing this here.
Also note that you have incorrectly used the class fluid-container instead of container-fluid, which will affect your padding. I've corrected that in the fiddle abopve, and the snippet below:
#media screen and (min-width: 768px) {
.navbar-nav {
float: none !important; /* StackSnippets require more specificity */
}
.navbar-nav li {
width: calc(100% / 3);
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<nav class="navbar">
<div class="container-fluid">
<ul class="nav navbar-nav navbar-inverse">
<li class="nav_page active">
Home
</li>
<li class="dropdown">
<a data-toggle="dropdown" class="dropdown-toggle" href="#">Dropdown
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li>National</li>
<li>Geo</li>
<li>Team Pictures</li>
</ul>
</li>
<li>About us</li>
</ul>
</div>
</nav>
EDIT
To additionally ensure that the titles are centralised, you're looking to add a width to .navbar-nav li that is 100% divided by the number of columns. COnsidering you have three columns, you divide by three:
.navbar-nav li {
width: calc(100% / 3);
}
Note that like the removal of the float, this should go inside of the media query.
I've created a new fiddle showcasing this here.
Hope this helps! :)
I must be doing something unusual, as the related questions and answers I've found so far on Stack Overflow aren't working for me. I'm new to css, so the answer may be obvious.
I prefer the solution to avoid !important, and if possible, only apply to the site header (e.g. not anywhere else on the site; that is, only apply to content inside block with id="my-block").
Also, would like solution to work for all levels in the nav (first, second, etc.).
This is what I tried:
.navbar .navbar-default > li > a:hover {
background-color: #FFFF00;
color: #FF0000;
}
Here's my code that runs along the top of my site:
<nav id="my-block" class="navbar navbar-default navbar-static-top navbar-default-siteheader navbar-inner-siteheader">
<div class="container">
<div class="collapse navbar-collapse in" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
Menu1<span class="caret"></span>
<ul class="dropdown-menu">
...
</ul>
</li>
<li class="dropdown">
Menu2<span class="caret"></span>
<ul class="dropdown-menu">
...
</ul>
</li>
</ul>
</div>
</div>
</nav>
Change
.navbar .navbar-default > li > a:hover
to
#my-block.navbar li a:hover
You can add your customize id in parent element like :-
<div **id="custom-nav-head"**>
<ul>
<li>Link</li>
</ul>
</div>
and then in css file, use below
**#custom-nav-head** .navbar .navbar-default > li > a:hover {
color: your color
}
if still its not work so then use !important property. Like :-
**#custom-nav-head** .navbar .navbar-default > li > a:hover {
color: your color **!important**;
}
Try this:
a.dropdown:hover{
background-color://whatever colour
}
HTML :
<nav class="header"> <img src="smiley.gif" class="logo">
<ul class="navigation">
<li id="a" class=""><span></span>A
</li>
<li id="b" class=""><span></span>B
</li>
<li id="account" class="right"> <span></span>Test Test
<ul class="dropdown">
<li>Log out
</li>
</ul>
</li>
</ul>
</nav>
From a previous question I was told to use inline-block to get the list to sit on the same line as the image (logo). however when I make the image the full height of the header it still drops the list down. What am I doing wrong?
JSFiddle
Change in .navigation class position from relative to absolute.
.navigation {
position: absolute;
display: inline-block;
z-index: 1000;
}
fiddle
I'm designing a website using Twitter's Bootstrap, and I'm having difficulty with the responsive navbar. In bootstrap, the navbar allows a mobile user to click an icon to extend the navbar and display navigation links. I'm unable to find how to adjust the maximum height... when I try and use one of the drop down bars, the navbar doesn't change size accordingly, and the user is unable to see any of the links.
Thanks for any help you can provide.
-A
EDIT: here's the code that I'm using for the navbar (html) the css that I'm using is the standard bootstrap.css and bootrstrap-responsive.css:
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="brand" href="http://example.com">organization</a>
<div class="nav-collapse collapse">
<ul class="nav">
<li>Home</li>
<li class="active">Contact</li>
<li>Now Playing</li>
<li class="dropdown">
Public Resources <b class="caret"></b>
<ul class="dropdown-menu">
<li>Observatory</li>
<li>Planetarium</li>
<li class="divider"></li>
<li class="nav-header">For Teachers and Schools</li>
<li>Programs</li>
<li>Host an Event</li>
<li>Educational Initiatives</li>
</ul>
</li>
<li class="dropdown">
Undergraduate Resources <b class="caret"></b>
<ul class="dropdown-menu">
<li>Observatory</li>
<li>Planetarium</li>
<li class="divider"></li>
<li class="nav-header">Physics</li>
<li>Physics Homepage</li>
<li>Physics and Astronomy</li>
</ul>
</li>
<li>Volunteer</li>
<li>FAQ</li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div>
The default navbar html code is the following:
<div class="navbar">
<div class="navbar-inner">
<a class="brand" href="#">Title</a>
<ul class="nav">
<li class="active">Home</li>
<li>Link</li>
<li>Link</li>
</ul>
</div>
</div>
And if you inspect the navbar element you will find that the inside div (navbar-inner) has the class:
.navbar-inner {
min-height: 40px;
}
You can remove this value and find that the navbar remains the same height, that's normal, because the height of the navbar is set to "auto". Therefore if you remove the min-height the height will depend of the link tags padding, inside the <ul></ul>, and the <a class="brand"></a> padding as well.
.navbar .nav > li > a {
float: none;
**padding: 10px 15px 10px;**
color: #777;
text-decoration: none;
text-shadow: 0 1px 0 #FFF;
}
.navbar .brand {
display: block;
float: left;
**padding: 10px 20px 10px;**
margin-left: -20px;
font-size: 20px;
font-weight: 200;
color: #777;
text-shadow: 0 1px 0 #FFF;
}
If you change it, you will find that the height of the "navbar" parent will automatically change. You can also maintain the min-height property and just change its value, adjusting the padding of the elements I've mentioned above.
For the responsive part, you can edit all the styles in the bootstrap-responsive.css, inside the specific media query for the resolution that you want to edit.
EDIT: Just saw your HTML, check the padding of your link tags inside the navbar, reduce it, change the .navbar-inner min-height too, and play with the values.
Ok, the way I fixed the first part (having a header that didn't resize when I wanted to) was by changing the min width value in the bootstrap-responsive.css like so:
#media (min-width: 1200px) {
.nav-collapse.collapse {
height: auto !important;
overflow: visible !important;
}
}
where 1200px was changed to 1200 from 980. Tricky tricky... for the record, it's on line 1104.