css - 100%的奇怪计算

标签 css margins

我有以下结构和布局:

jsbin

问题: 为什么 margin-top: 6% 计算为 div#content 的像素多于 div#header 的像素?

注意:两个元素的父元素都设置了height: 100%,就像div#top-container 一样。

我有一种强烈的感觉,这与 div#headerdiv#content 是 float 的事实有关,但我真的可以'弄清楚为什么它会这样。

最佳答案

来自 http://www.w3.org/TR/CSS2/box.html#margin-properties

The percentage is calculated with respect to the width of the generated box's containing block. Note that this is true for 'margin-top' and 'margin-bottom' as well.

关于css - 100%的奇怪计算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9173901/

相关文章:

jquery - CKEditor 禁用所有文本样式

javascript - 如何在框架集中的 iframe 中更改 CSS

html - 如何将我的 Logo 插入横幅并居中对齐?

html - 边距和绝对位置无法正常工作

css - 如何处理 chrome 和 firefox 中的 css top 值差异?

android - 在 Android 中使用负边距是一种不好的做法吗?

html - 视差滚动效果有效,但我的图像不会固定到两侧和页面顶部

html - 为什么特定图像不会显示在 iPad 4 上的 Safari iOS 上?

html - 使用 CSS 正确对齐换行文本

jquery - 如何让这个 jQuery 动画函数从下到上工作?