简体   繁体   English

水平和垂直列表项之间的间距不同

[英]Different spacing between horizontal and vertical list item

The space between horizontal and vertical list item appears differently, even through the margin, padding, height and width are exactly the same for both layouts. 水平和垂直列表项之间的空间显示不同,即使两种布局的边距,填充,高度和宽度也完全相同。 I would like them to be the same, I know I can manually adjust the margins or paddings, but why are they not the same, is there a simple way to keep them consistent? 我希望它们相同,我知道我可以手动调整边距或填充,但是为什么它们不相同,是否有一种简单的方法可以使它们保持一致? thanks. 谢谢。

HTML HTML

<ul class="horizontal">
    <li></li>
    <li></li>
    <li></li>
</ul>
<div class="clear"></div>
<ul class="vertical">
    <li></li>
    <li></li>
    <li></li>
</ul>

CSS CSS

ul li {
    padding: 0;
    margin: 10px;
    width: 13px;
    height: 13px;
    background: #333333;
    border-radius: 50%;
}

.horizontal li {
    float: left;
}

see the result here: http://jsfiddle.net/bingjie2680/3ZbkQ/ 在此处查看结果: http : //jsfiddle.net/bingjie2680/3ZbkQ/

The vertical li 's margin are collapsing . 垂直li的边距正在崩溃 You can get around this with: 您可以通过以下方法解决此问题:

.vertical li {
    float: left; /*a floated box's margin does not collapse with any other box */
    clear: left; /* Push each succeeding li to a new line, 
                    though not needed on the first */
}

Updated fiddle 更新的小提琴

Read this: http://www.w3.org/TR/CSS21/box.html#collapsing-margins Your vertical margin is collapsing, cause your elements are 'next' to each other. 阅读以下内容: http : //www.w3.org/TR/CSS21/box.html#collapsing-margins您的垂直边距正在崩溃,因为您的元素彼此“相邻”。 In difference to that, horizontal margins are not collapsing. 与此不同的是,水平边距没有崩溃。

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

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