简体   繁体   English

剩余浮点时将LI居中对齐

[英]Center align LI when there is Float left

Folllowing is my jsfiddle in which I am trying to center align the list items <li> into <ul> . 跟随是我的jsfiddle,在其中我试图将列表项<li>居中对齐到<ul> Only problem is lis are set to float left and I can not remove this condition . 唯一的问题是lis设置为向左浮动,我无法删除此情况 Kindly let me know is there a way to tackle float left and make lis center aligned generically (in responsive manner)? 请让我知道是否有一种方法可以解决浮动问题并使lis中心一般地对齐(以响应方式)?

http://jsfiddle.net/AqRJA/2/ http://jsfiddle.net/AqRJA/2/

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

#nav li {
    float: left;
}

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

Demo Fiddle 演示小提琴

Why not simply add: 为什么不简单地添加:

#nav ul{
    display:inline-block;
}

Try like this: DEMO 尝试这样: DEMO

CSS: CSS:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM