I’ve got a set of li‘s containing text which I would like to be displayed and centered horizontally within their ul with CSS. I can’t seem to get this to work, another answer suggested using display:inline but this did nothing.
Here’s the code:
header li {
margin-left:20px;
margin-right:0px;
border-left:1px #FFF solid ;
float:left;
color:#FFF;
padding:2px 2px 2px 2px;
margin-bottom:10px;
text-align:center;
}
header ul {
width:321px;
margin-left:auto;
margin-right:auto;
background:url(repeatback.png);
height:30px;
}
requested html:
<ul>
<li>About</li>
<li>Portfolio</li>
<li>Resume</li>
<li>Links</li>
<li>Twitzar</li>
</ul>
I’m assuming you want to have your text centered within the list item? You need to specify a width on the element for
text-align: centerto work correctly.For an example refer to this fiddle: http://jsfiddle.net/sUxnK/1
Note, that the css was tweaked slightly to show the centered text.