Horizontal justified menu in CSS with bar in space -
this question has answer here:
- how justify horizontal list? 9 answers
i have used code this question create horizontal menu each item evenly spaced.
here version:
<div id="navigation"> <ul> <li class="first"> <a href="#" title="home page">home</a> </li> <li> <a href="#">about us</a> </li> <li> <a href="#">what we cover</a> </li> <li> <a href="#">monitoring agencies</a> </li> <li> <a href="#">publishers</a> </li> <li> <a href="#">news</a> </li> <li> <a href="#">contact us</a> </li> <span></span> </ul> </div> and css:
#navigation { text-align: justify; } #navigation ul span { display: inline-block; position: relative; width: 100%; height: 0; } #navigation ul { display: inline; list-style: none; } #navigation ul li { display: inline } #navigation ul li { display: inline; border-right: solid 1px #ccc; } #navigation ul li.last { border-right: none; } is there way make vertical lines move right such halfway between end of tags , end of li tags?
here fiddle.
i've added answer here.
hack using elements spacer motif
fiddle reference: http://jsfiddle.net/audetwebdesign/bf6ey/
consider following html:
<div id="navigation"> <ul class="navigation"> <li class="first"> <a href="#" title="home page">home</a> </li> <li class="spacer-motif">|</li> <li> <a href="#">about us</a> </li> <li class="spacer-motif">|</li> ... <li class="spacer-motif">|</li> <li> <a href="#">contact us</a> </li> </ul> </div> i added list item between links: <li class="spacer-motif">|</li> (yes, cringe also...).
the css follows:
#navigation { padding: 0 20px; /* add spacing @ left/right edges of list */ } #navigation ul { display: table; width: 100%; list-style: none; margin: 0; padding: 0; } #navigation ul li { display: table-cell; text-align: center; width: 1%; /* force cell shrink-to-fit text */ outline: 1px dashed blue; } #navigation ul li.spacer-motif { width: 10%; /* force spacers take lot of space */ outline: none; } #navigation ul li { white-space: pre; } the layout based on using table display types.
for ul, use display: table , set width 100%. remember 0 out margin , padding values.
for li, use display: table-cell , text-align: center.
the trick force table cells shrink-to-fit text labels setting width: 1%, , then, li.spacer-motif, set width: 10% force spacers expand (evenly) fill line.
to keep text links wrapping 2 or 3 lines, set white-space: pre in <a> elements (the links).
cleaning semantics
the problem here link texts vary in width , makes impossible use table-cell's right or left border , centered text. spacing vary among links , left/right border not evenly spaced between link texts.
the way around add elements. used pipe (|) suppose add pseudo-element 1px border , center , on.
however, if elements problem, inserted using jquery or javascript.
ie 7 support - hack css
if need ie7 support, need adjust css according following:
css: table , table-cell replacement ie7
Comments
Post a Comment