I am new to css and html5 and trying to get my menu bar to work properly. It is a horizontal menu bar with drop down feature. Before I centered the menu bar there were no spaces between the nav buttons and the drop down buttons. After centering it they now have a space between them which is irritating because when you go between them, more so on the drop down, you lose the drop down menu because of the space. Therefore I am trying to remove the space (not the borders) between the buttons. Thank you very much for your help here is the code:
CSS
/* START NAV MENU */
nav {
background-color:#333333;
height:40px;
width:100%;
}
nav ul {
font-family: Sonoma, Arial;
font-size: 20px;
margin: 0;
padding: 0;
list-style: none;
text-align:center;
}
nav ul li {
display: inline-block;
position: relative;
}
nav li ul {
display: none;
}
nav ul li a {
display: inline-block;
text-decoration: none;
background: #666666;
color: #ffffff;
padding: 5px 20px 3px 15px;
margin-left: 1px;
white-space: nowrap;
height:30px; /* Width and height of top-level nav items */
width:90px;
text-align:center;
border-right: 3px solid black;
border-left: 3px solid black;
}
nav ul li a:hover {
background: #999999;
}
nav li:hover ul {
display: block;
position: absolute;
height:30px;
}
nav li:hover li {
float: none;
font-size: 11px;
}
nav li:hover a {
background: #534635;
height:30px; /* Height of lower-level nav items is shorter than main level */
}
nav li:hover li a:hover {
background: #999999;
}
nav ul li ul li a {
text-align:left;
}
/* END NAV MENU */
HTML FOR NAV:
<nav>
<ul>
<li><a href="/">Home</a></li>
<li><a href="/about">About Us</a>
<ul>
<li><a href="/crew">Our Crew</a></li>
<li><a href="/history">History</a></li>
<li><a href="/vision">Vision</a></li>
</ul>
</li>
<li><a href="/products">Services</a>
<ul>
<li><a href="/carpentry">Carpentry</a></li>
<li><a href="/waterproof">Waterproofing</a></li>
<li><a href="/concrete">Concrete</a></li>
<li><a href="/masonry">Masonry</a></li>
<li><a href="/prop">Property Maintenance</a></li>
<li><a href="/metal">Metal Construction</a></li>
<li><a href="/design">Interior Design</a></li>
<li><a href="/demo">Demo & Salvage</a></li>
</ul>
</li>
<li><a href="/services">Portfolio</a>
</li>
<li><a href="/contact">Contact</a>
<ul>
<li><a href="/email">Via Email</a></li>
<li><a href="/contact_form">Web Form</a></li>
<li><a href="/pigeon">Carrier Pigeon</a></li>
</ul>
</li>
</ul>
</nav>
if you could please explain what the changes are to make this happen and why it changes it I would greatly appreciate it thanks!
Floating is indeed one option but you have others that may be more preferable as they allow you to keep the inline-block style and its associated benefits.
Chris Coyier's article Fighting the Space Between Inline Block Elements http://css-tricks.com/fighting-the-space-between-inline-block-elements/ details each one, but in summary it's caused by the white space between your closing </li>
and the next <li>
.
Your options are as follows:
</li>
from each list item.<li><a href="/crew">Our Crew</a>
<li><a href="/history">History</a>
<li><a href="/vision">Vision</a>
It's valid HTML5 and won't break anything.
<li><a href="/crew">Our Crew</a></li><li><a href="/history">History</a></li>
<li><a href="/vision">Vision</a>
<li><a href="/crew">Our Crew</a></li><!--
--><li><a href="/history">History</a></li><!--
--><li><a href="/vision">Vision</a></li>
ul {
font-size: 0;
}
a {
margin-right: -4px;
}
Personally I prefer removing the closing tag as the others look too messy and font-size: 0 doesn't work out too well when using relative sizes, but it's up to you, they're all good in their own way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With