开发者

How to center align <li> items when it goes to 2nd line?

I want to make a Un-ordered list using single <ul> .... </ul>

How to align 2nd line in 开发者_开发百科center?

How to center align <li> items when it goes to 2nd line?

I created JSFiddle here http://jsfiddle.net/jitendravyas/JWHQQ/ to test


To align <ul> element in the center, set left and right margins to auto:

ul{ text-align:center;width:450px;margin-left:auto;margin-right:auto}
li{ float:left;padding:15px}

To align both lines of <li> to center, use display: inline as suggested by domanokz. But in this case <li> lose their margins and paddings. To keep them, set display to inline-block:

ul{ text-align:center;width:450px;}
li{ display:inline-block;padding:15px;}


Make the li's inline... You don't have to set the float:left

ul{ text-align:center;width:450px}
li{ display:inline;padding:15px}


does this do the trick?

http://jsfiddle.net/JWHQQ/5/

I made the li inline elements instead of making them float left.


This seems to be the best solution.

ul{ text-align:center;width:450px magin:0 auto}<br>
li{ display:inline;padding:15px}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜