I'm working at a justified navigation bar. Some of the menu items are in two lines some have only one line. How can I manage it, that all menu items are vertically centered?
My HTML
<nav>
<div role="navigation" class="col-lg-12 hidden-xs hidden-sm hidden-md navi">
<ul class="nav nav-justified">
<li class="active">
<a href="#" >
<span class="glyphicon glyphicon-home active"></span>
</a>
</li>
<li>
<a href="rooms_prices.html" >
Rooms & Prices
</a>
</li>
<li>
<a href="location.html" >
Location
</a>
</li>
...
<li>
<a href="specials.html">
Specials & Events
</a>
</li>
<li>
<a href="contact.html">
Contact
</a>
</li>
</ul>
</div>
</nav>
My LESS:
nav {
margin: 0;
padding: 0;
}
.nav-justified {
width: 100%;
hight: 60px;
> li {
float: none;
alignment-adjust: middle;
> a {
display: block;
text-align: center;
}
}
THX for your hints!
EDIT:
Sorry I've messed up the code. I've left the -Tag out because there ave mor div sections with different navigation bars for several display sizes.
You have a ton of problems here, your markup is incorrect and you're trying to apply styles to elements that don't exist.
You're targeting nav, you have no nav element so you should be using .nav to target the class you've applied the div parent.
<div role="navigation"col-lg-12 hidden-xs hidden-sm hidden-md navi">
This is not valid HTML, it should be:
<div role="navigation" class="col-lg-12 hidden-xs hidden-sm hidden-md navi">
If you have nav items where the text drops down onto two lines considering your menu is justified I'd suggest that your text is too long and you should instead use some CSS3 truncation in conjunction with storing the full name of the menu item in its title attribute so it shows on hover - stretching out your other menu items is going to look strange and will require some hacking to achieve.
.nav-justified a {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
The issue you will have trying to vertically center a justified nav is that usually you would make the list items display: inline-block and vertically center them that way, but as justified items they are display: block by default. Additionally Bootstrap applies the border styles directly to the anchors, not the list items, so even if you vertically centered them you'd have borders out of alignment.
Related
I was able to center my navbar with the CSS below. Now I want to put another element but pull that to the right. However, when I add the icon, it drops down to the next line. How do I center my navbar and add the icon, while keeping everything inline?
This is a piece of my navbar with the css.
<div class="collapse navbar-collapse" id="myNavbar" style="text-align: center;">
<ul class="nav navbar-nav">
<li >Home</li>
<li >About</li>
<li >Get Help</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><span class="glyphicon glyphicon-search pull-right" aria-hidden="true" style="font-size:18px; display: inline-block;"></span></li>
</ul>
</div>
CSS:
#media (min-width: 708px){
.navbar-nav{
float:none;
margin: 0 auto;
display: table;
table-layout: fixed;
}
}
One option is to add the "top" property on the element then give it a negative value to correctly position your search icon.
.search {
top: -50px;
font-size: 18px;
}
If necessary, adding additional navigation links wont't break style .
See my plunker
Also, you may take out the styles in your HTML tags.
I have an intranet page that has a large navbar that causes the sub menus to display off the screen if the user has a small monitor. My idea was to have the navbar scroll but when I use overflow in the CSS a vertical scroll bar appears when the sub menus open. I want the sub menus to display OUTSIDE of the div that contains the navbar. I'm open for all ideas including reorganizing my page if I have to.
Sample HTML is:
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="scrollmenu">
<li class="menu-item dropdown dropdown-submenu">
Some Text
<ul class="dropdown-menu">
<li class="menu-item dropdown dropdown-submenu">
<ul class="dropdown-menu scrollable-menu">
<li class="menu-item">
<a id="" class="pdf" href="#"></a>
<a id="" class="pdf" href="#"></a>
<a id="" class="pdf" href="#"></a>
<a id="" class="pdf" href="#"></a>
<a id="" class="pdf" href="#"></a>
</li>
</ul>
</li>
</li>
</div>
</div>
</div>
And the CSS I'm using is (I found this CSS on W3schools.com):
div.scrollmenu {
background-color: #333;
overflow: auto;
white-space: nowrap;
width: 50%;
}
div.scrollmenu a {
display: inline-block;
/*color: white;*/
text-align: center;
padding: 14px;
text-decoration: none;
}
div.scrollmenu a:hover {
background-color: #777;
}
The problem I'm having is that in order to get the scroll bar I have to use the overflow: auto setting in the CSS. But when I do that it causes the sub menus to appear in the same div which causes a vertical scroll bar to appear when a sub menu is displayed. Without the overflow setting the sub menus display outside of the div which is the desired behavior; but, of course, the scroll bars do not appear.
Help please.
FYI, I'm getting ready go home for the weekend and will followup with this on Monday.
Thanks in advance.
The scrolling nav bar is not a good design for a nav bar with sub menus. We decided to change the nav bar to an Accordion style of navigation.
Trying to create a navigation menu at the top of the page, but the images are spaced too far away from each other and then they wrap. How do I bring them closer together?
CSS:
.weddingMenuIcon{
width:30%;
}
HTML:
<ul class="list-inline">
<li>
<img src="~/images/home.svg" class="img-responsive weddingMenuIcon" />
</li>
<li>
<img src="~/images/home.svg" class="img-responsive weddingMenuIcon" />
</li>
<li>
<img src="~/images/home.svg" class="img-responsive weddingMenuIcon" />
</li>
</ul>
If I were building this as a centered navigation I would apply inline: block to the list items and then use a margin to define the spacing between them.
See this jsFiddle
.list-inline li {
display: inline-block;
margin: 0 40px; /* Items have 40px spacing between */
}
The fix was simply changing the width from using percentage to using fixed pixel width.
I realize this has probably been answered before, and if so, please direct me to another page.
I have a menu bar that goes horizontally across my page. I have several links and I want spacing so the links will fill the width of the nav.
CSS:
nav {
width:100%;
float:left;
text-align:center;
}
HTML:
<nav id="menu">
<a id="home" href="index.html">Home</a>
<a id="link" href="link.html">Link</a>
<a id="another" href="really.html">Another</a>
<a id="lalala" href="stupidcode.html">Lalala</a>
<a id="oneMore" href="example.html">One More</a>
</nav>
Using display: table-cell on the elements inside nav works.
Fiddle: http://jsfiddle.net/mnmxm2h0/
On this page there's a menu in the right sidebar that is composed of a HTML list with this structure:
<ul class="nav nav-pills nav-stacked">
<li class="active">
<i class="icon-home"></i> Home
</li>
<li>
Development
</li>
<li>
Management
</li>
<li>
Learning
</li>
<!-- more menu entries -->
</ul>
Notice that some menu entries have (font) icons to the left of the label, whereas others don't. This makes the menu appear rather unsightly, because the labels are not vertically aligned.
Is there are any way to vertically align the labels, ideally without introducing additional HTML elements (because that messes up some immediate descendant rules that are defined within Bootstrap itself)?
Try this:
.nav-pills.nav-stacked > li > a {
padding-left: 25px;
}
.nav-pills.nav-stacked > li > a > i {
position: absolute;
margin-left: -25px;
}
It takes the icons out of the flow, puts the text 25px to the right, and then positions the icons 25px to the left