html - Stretch UL list as horizontal navigation bar evenly spaced... with spaces on outer margins as well -
i spent chunk of evening trying horizontal navigation bar , managed set , centered, this tip. however, code gives items evenly spaced , pressed against edges of page (or region, or div, or whatever they're inside).
what i'd them evenly spaced across inside , spaces of same size appear on outer margins, i.e. before first , after last items, well.
for reference, here's html:
<ul id = "nav"> <li>accueil</li> <li>recherche</li> <li>contact</li> </ul>
and here css:
#nav { width: 100%; text-align: justify; margin: 0 0 3em 0; padding: 8px; list-style: none; border-bottom: 1px solid #ccc; border-top: 1px solid #ccc; } #nav:after { content: ''; display: inline-block; width: 100%; } #nav li { width: 15%; display: inline-block; padding: 4px 15px; text-align: center; text-decoration: none; background-color: #f2f2f2; border: 1px solid #ccc; border-radius: }
is there way without specifying fixed margins or artificially "squeezing" contents of region? appreciated indeed. many in advance!
update
actually have limit 800px maximum in width. there's no way fluidly? tried javascript calculate spaces left , right should be, points begin spill on next line if go above 5%.
i think might missing on precisely how "before" , "after" aspects behave when list horizontalized. @ point better off using set of divs bullet points? (if list ever becomes dynamic makes page less proper, simple project doubt problem.)
thanks again!
update bis
found great solution. here is:
#nav { display: flex; justify-content: space-around; text-align: justify; width: 100%; margin: 0; padding: 8px 0px; list-style: none; border-bottom: 1px solid #ccc; border-top: 1px solid #ccc; } .navitem { position:relative; width: 15%; display: inline-block; padding: 4px 15px; text-align: center; text-decoration: none; border: 1px solid #ccc; border-radius: 3px; } .navspan { position:absolute; width:100%; height:100%; top:0; left: 0; display: block; }
try code
#nav { width: 100%; text-align: justify; margin: 0 0 3em 0; padding: 8px; list-style: none; border-bottom: 1px solid #ccc; border-top: 1px solid #ccc; } #nav:after { content: ''; display: inline-block; width: 100%; } #nav li { width: 10%; display: inline-block; padding: 4px 2%; text-align: center; text-decoration: none; background-color: #f2f2f2; border: 1px solid #ccc; margin-right:12%; } #nav:before { width: 15%; display: inline-block; padding: 4px 15px; text-align: center; text-decoration: none; content:'' }
you'll need lower margin-right on narrow screens (under 780px), because % number becomes inexact @ point should enough have started. see fiddle here
Comments
Post a Comment