Reputation: 678
I have an unordered vertical list..
<div>
<ul>
<li>home</li>
<li>portfolio</li>
<li>about</li>
<li>contact</li>
</ul>
</div>
css:
div {
width: 600px;
}
ul {
text-align: center;
}
What I really want is the list to be text aligned left, while the ul is still horizontally in the center. is there a way to that?
Upvotes: 1
Views: 69
Reputation: 241258
You can do something like this to center dynamically generated content of varying widths:
div { text-align: center; }
ul { display: inline-block; }
li { text-align: left; }
Alternatively, you can set a defined width on the parent, and use margin:0px auto
, assuming it is a block
level element.
ul {
width: 100px;
margin: 0px auto;
}
Upvotes: 3