css - 试图显示固定高度的 DIV。为什么后续的 DIV 显示在固定高度的 DIV 之上?

标签 css html height

这很奇怪;我正在指定一个 DIV 的 height,但浏览器似乎在它上面显示了其他 DIV。一个例子在 http://jsfiddle.net/x48v4/ .

我尝试明确指定 display: block; 但没有骰子。还尝试指定 min-height 但这也不起作用。我读到一个有前途的技巧,涉及 clear: both; 但这也无济于事。

在 JSFiddle 示例中,我只希望红色 DIV 直接显示在蓝色 DIV 下方。感谢您提供的任何帮助!

<html>
<body style="font-family: arial, helvetica, sans-serif; font-size: 11pt; font-weight: bold; line-height: 1.5;">

<div style="width: 300px; text-align: center; margin: 0px auto;">

    <div style="height: 300px; background: #9999ff;">
        <br>
        This DIV has a blue background and is 300px tall.&nbsp; I want the red DIV below to display underneath this blue header.<br>
        &nbsp;
    <div>

    <div style="background: #ff5555;">
        But instead, this DIV is "superimposed" over the blue DIV's background-&nbsp; why is that?<br>
        I want this to be underneath the blue DIV instead.
    <div>

</div>

</body>
</html>

最佳答案

也将此作为答案发布。 div 未正确关闭 - 对于两个框。

这是更新后的代码:

<html>
<body style="font-family: arial, helvetica, sans-serif; font-size: 11pt; font-weight: bold; line-height: 1.5;">

<div style="width: 300px; text-align: center; margin: 0px auto;">

    <div style="height: 300px; background: #9999ff;">
        <br>
        This DIV has a blue background and is 300px tall.&nbsp; I want the red DIV below to display underneath this blue header.<br>
        &nbsp;
    </div>  <!-- closed the div here -->

    <div style="background: #ff5555;">
        But instead, this DIV is "superimposed" over the blue DIV's background-&nbsp; why is that?&nbsp; I want this to be underneath the blue DIV instead.
    </div>  <!-- closed the div here -->

</div>

</body>
</html>

关于css - 试图显示固定高度的 DIV。为什么后续的 DIV 显示在固定高度的 DIV 之上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20730607/

相关文章:

html - 如何语义标记类别标题

html - 不会显示 CSS 背景图像

c - 二叉搜索树 - 迭代检查高度

jquery - 分析DIV高度非函数的脚本

css - 如何知道元素高度或宽度是否在 javascript/css 中设置?

css - reactstrap <UncontrolledDropdown> 正在离开视口(viewport),mr/ml-auto 和 float-right/left 不工作

html - 在 user#show 中显示最喜欢的食谱列表

php - 在一页中使用多个上传按钮

html - 无法重叠 DIV

css - flex 对齐内容中心