简体   繁体   English

将列表与 6 个项目水平对齐?

[英]Horizontally aligning a list with 6 items?

I can't seem to figure out how to get 6 list items (with spacing) to horizontally align evenly across the site.我似乎无法弄清楚如何让 6 个列表项(带间距)在整个站点上水平对齐。 The width of the page is 1000px, this is what I have...页面的宽度是1000px,这就是我所拥有的...

<ul id='mp_locations'>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
<style>
#mp_locations {
clear:both;
list-style:none;
padding:0;
margin:0;
width: 1000px;
}
#mp_locations li {
float:left;
width:180px;
list-style:none;
height:100px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
background-color: #F5F5F5;
padding:0;
margin:0;
margin-left:10px;
width:15%;
}
#mp_locations li:first-child {
margin-left:0;
}
</style>

The issue with this is that 15% is too small but 16% is too big.问题在于 15% 太小了,但 16% 太大了。 Since you can't do decimals (to the best of my knowledge) I can't set it to a set amount.由于您不能进行小数(据我所知),因此我无法将其设置为固定数量。 So basically, how can I get 6 boxes to line up evenly across the page?所以基本上,我怎样才能让 6 个盒子在页面上均匀排列?

Hey now define with of your id #mp_locations li 15.83%嘿,现在定义with您的ID #mp_locations li 15.83%

#mp_locations li {
width:15.83%;
}

live demo http://tinkerbin.com/kzx7nX9s现场演示http://tinkerbin.com/kzx7nX9s

there are two width rules in #mp_locations li you could change it to #mp_locations li有两个宽度规则,您可以将其更改为

#mp_locations li {
float:left;
width:156px;
list-style:none;
....
margin:0;
margin-left:10px;

And I advice you to change the margin too: margin: 0px 5px;我建议您也更改边距: margin: 0px 5px;

dont repeat same style attribute un necessarily.不一定重复相同的样式属性。 you can get the desired output just by changing margin-left see below:您只需更改margin-left即可获得所需的输出,如下所示:

css css

#mp_locations {
clear:left;
list-style-type:none;
padding:0;
margin:0;
width: 1000px;
background-color:red;
overflow:hidden;
}
#mp_locations li {
float:left;
height:100px;
border-radius:5px;
background-color: #F5F5F5;
margin-left:8px;
width:16%;
display:inline;
}
#mp_locations li:first-child {
margin-left:0;
}

html html

<ul id='mp_locations'>
<li>d</li>
<li>f</li>
<li>d</li>
<li>ff</li>
<li>fff</li>
<li>ddfdfdfd</li>
</ul>

Working DEMO工作演示

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

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