Proper spacing for multiple word links in justify aligned horizontal nav bar?
I'm building a text-based navigation bar, evenly spaced across the width of a parent div, but I'm having a problem keeping certain navigation items grouped together. Each word, instead of each list item, distributes across the entire width of the div. Is there a way to distribute each list item evenly within the div, but keep longer items, like "/painting & Mixed media" properly spaced? I also have a phantom space in front of the first link I can't find, so it's not exactly justified the way I would hope.
To clarify: The posted code displays the link to "/Painting & Mixed Media" with additional spacing between each word. Example below, where dashes represent spaces in the nav menu:
Currently: .../Prints---/Illustration---/Painting---%---Mixed---Media---/About---/Blog...
Desired: .../Prints---/Illustration---/Painting-&-Mixed-Media---/About---/Blog...
Here's the CSS:
.navbar{
font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
font-size:16px;
text-decoration: none;
text-align:justify;
width: 800px;
}
.navbar * {
display: inline;
}
.navbar span {
display: inline-block;
position: relative;
width: 100%;
height: 0;
}
a.nav:link {color:#000; text-decoration: none;}
a.nav:visited {color:#000; text-decoration: none;}
a.nav:hover {color:#6CC; text-decoration: none;}
a.nav:active {color:#F90; text-decoration:none;}
And the HTML:
<div class="navbar">
<ul>
<li><a href="index.html" class="nav">/home</a></li>
<li><a href="design.html" class="nav">/design </a></li>
<li><a href="prints.html" class="nav">/prints</a></li>
<li><a href="illustration.html" class="nav">/illustration</a></li>
<li><a href="painting.html" class="nav"> /painting & mixed media</a></li>
<li><a href="about.html" class="nav">/about</a></li>
<li><a href="external_blog.html" class="nav">/blog</a></li>
<li><a href="cv.html" class="nav">/cv</a></开发者_如何转开发li>
</ul>
<span></span>
</div>
Demonstration fiddle
HTML:
<div class="navbar">
<ul>
<li><a href="index.html">/home</a></li>
<li><a href="design.html">/design </a></li>
<li><a href="prints.html">/prints</a></li>
<li><a href="illustration.html">/illustration</a></li>
<li><a href="painting.html">/painting & mixed media</a></li>
<li><a href="about.html">/about</a></li>
<li><a href="external_blog.html">/blog</a></li>
<li><a href="cv.html">/cv</a></li>
</ul>
<span></span>
</div>
CSS:
.navbar {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
font-size: 16px;
text-align: justify;
width: 800px;
}
.navbar * {
display: inline;
}
.navbar a {
display: inline-block;
text-decoration: none;
}
.navbar span {
display: inline-block;
width: 100%;
}
.navbar a:link,
.navbar a:visited {color:#000;}
.navbar a:hover {color:#6CC;}
.navbar a:active {color:#F90;}
精彩评论