How do I center floated list items?

試著忘記壹切 提交于 2019-12-03 13:34:06

By making the items display inline you can then align them as text. Setting the line height fixed wrapping issue.

 #nav{
        text-align: center;
        line-height:30px;

    }

    #nav li {
        list-style:none;
        margin: 0 5px;
        display:inline;
        border:gray solid 1px;
    }

Working demo can be seen here: http://jsfiddle.net/AqRJA/1/

Try changing your CSS to:

#nav ul{

margin-right:auto;
margin-left:auto;
text-align:center;

}

#nav ul li{
display:inline;
background-color:#333;
color:#fff;
padding:15px;
margin:10px;

}

Cheers,

Cynthia

give width to ul

replace your class with this one

   #nav ul {
       margin-right: auto;
       margin-left: auto;
       width:400px;
   }
TimSPQR

I've been through the same thing sooooo many times.

You can't center anything with % layout, you have to be specific in pixels or ems.

So I changed your code to give the div a specific width and then centered it.

`<div class="centerme">
      <!--put your stuff here-->
   </div>`   

Here's the jsfiddle:

http://jsfiddle.net/EqNtH/

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!