HTML CSS : odd behavior that I can't understand, 添加边框时多余空间消失

标签 html css

这里是 css/hmtl 新手。我一直在搞乱 div,我遇到了一些我无法弄清楚/无法解释的奇怪行为。当它应该以 y 轴为中心时,我在“更多”链接下方获得了额外的空间。

这是代码:

#show-rec-box {
    clear: both;
    width: 100%;
    height: 286px;
    border-bottom: 1px solid #ececec;  

}

但是当我把它改成这个时,多余的空间就消失了!

#show-rec-box {
    clear: both;
    width: 100%;
    height: 286px;
    border-bottom: 1px solid #ececec; 
    border: 1px solid #911; 
}

没有额外边框的完整代码:http://jsfiddle.net/8q3Ca/ 带有额外边框的代码:http://jsfiddle.net/8q3Ca/1/ 任何想法发生了什么?非常感谢!

最佳答案

您在 #rec-title 上有 margin-top。这是 margin 崩溃 - http://www.w3.org/TR/CSS2/box.html#collapsing-margins尝试对父 block 使用“溢出:自动”。类似问题Child elements with margins within DIVs

http://jsfiddle.net/fliptheweb/8q3Ca/2/

关于HTML CSS : odd behavior that I can't understand, 添加边框时多余空间消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8144975/

相关文章:

javascript - 在 JavaScript 中重新加载页面后保持 HTML 表格顺序

javascript - 无法接收使用 ajax 发布的 js 数组

html - 媒体查询在移动设备上不起作用,但在桌面上效果很好

jquery - 如何打破边距、填充和背景属性?

javascript - 无论如何,是否可以使用 Angular2 轻松地将自定义字符串绑定(bind)到 id 和 html 元素中的 for ?

javascript - Mapbox 悬停弹出窗口不起作用

javascript - 如何在执行第二次搜索时重置 CSS(从第一次搜索中删除搜索结果)

css - IE7 切断 span 标签上的边框

javascript - jQuery Fullpage - 在菜单上用水平线显示当前部分位置

css - 图片右侧有 2 行文字