html - Centering UL navigation horizontally using CSS sprite background -
i have 4 element horizontal list using sprite image li background i've been trying centered in footer div. @ point think i'm running in circles randomly changing styles trying it. here's relevent css , html:
#footer-share-links { width:400px; text-align:center; margin:10px auto; background:#ff6666; border: 1px solid red; height:36px; } #footer-share-links ul { padding:0; position:relative; list-style-type:none; } #footer-share-links li { margin:0 auto; display:inline; float:left; text-align:center; position:absolute; } #footer-share-links li, #footer-share-links { height:36px; } #ftr_facebook {left:0px;width:25px;} #ftr_facebook {background:url('sprites/spriteglobal.2014-0001.png') 0 0;} #ftr_twitter {left:30px;width:26px;} #ftr_twitter {background:url('sprites/spriteglobal.2014-0001.png') -25px 0;} #ftr_gplus {left:61px;width:26px;} #ftr_gplus {background:url('sprites/spriteglobal.2014-0001.png') -77px 0;} #ftr_linkedin {left:93px;width:26px;} #ftr_linkedin {background:url('sprites/spriteglobal.2014-0001.png') -51px 0;}
the background , border on div me see box. html is:
<div id="footer-share-links"> <ul> <li id="ftr_facebook"><a href=""></a></li> <li id="ftr_twitter"><a href=""></a></li> <li id="ftr_gplus"><a href=""></a></li> <li id="ftr_linkedin"><a href=""></a></li> </ul> </div>
using centered red box div, list elements pushed left edge. if add margin:0 auto; ul stays same. if add margin-left:100px move towards center, don't want use fixed value unless absolutely have to.
here 1 way of doing it, try following css:
#footer-share-links { width:400px; text-align:center; margin:10px auto; background:#ff6666; border: 1px solid red; height:36px; line-height: 36px; } #footer-share-links ul { padding:0; margin: 0; list-style-type:none; } #footer-share-links li { margin: 0; display: inline-block; width: 50px; /* demo */ background-color: yellow; /* demo */ } #footer-share-links { display: block; /* or inline-block */ }
demo: http://jsfiddle.net/audetwebdesign/yn5mp/
as suggested earlier, remove floats , absolute positioning.
for parent container #footer-share-links
, set line-height
equal height
value, way vertical centering takes care of itself.
on ul
element, make sure 0 out margins.
finally, on li
elements, use display: inline-block
width recognized.
you can use id
names specify width's on individual li
elements needed.
on a
elements (links), use display: block
make link take width of li
element link has enough active/control area.
Comments
Post a Comment