【问题标题】:Why the top & bottom padding comes to floated element?为什么顶部和底部填充出现在浮动元素中?
【发布时间】:2014-08-31 17:53:29
【问题描述】:

一个疑问:

我为 div 赋予 float:left 并在 div 中放置另一个块元素,例如 h3。然后它给出填充顶部和底部。如果我删除 float: left 它不会提供填充。

html

<div class="one"><h3>Test with Float</h3></div>
<div class="clear">&nbsp;</div>
<div class="two"><h3>Test without Float</h3></div>

css

.one{
    background: grey;
    float:left;
    width: 100%;
}
.two{
    background: #DAD5C1;
      width: 100%;
}
.clear{
    clear: both;
}

http://jsfiddle.net/7yh3kuea/

【问题讨论】:

  • 请将您的代码放入问题中,或者根本不要费心链接到小提琴。不要绕过质量过滤器。
  • 不好的提问方式,但有趣的问题。
  • 感谢 rnrneverdies

标签: html css css-float


【解决方案1】:

它不是填充,而是在非浮动元素中被忽略的边距。

更多信息是here

【讨论】:

  • 对不起,我已经看过这个链接了。但不是很好理解。
猜你喜欢
  • 2010-11-26
  • 2011-11-02
  • 1970-01-01
  • 1970-01-01
  • 2022-11-10
  • 1970-01-01
  • 2012-07-15
  • 2018-04-01
  • 1970-01-01
相关资源
最近更新 更多