css - 与 float 行为混淆

标签 css

<!DOCTYPE html>
<html>
<head>
    <title>float</title>
    <style>
    .container {
        margin:0 auto;
        width:310px;
        height:500px;
        border:1px solid blue
    }

    .f {
        float:left;border: 1px solid red;width:100px;
    }
    </style>
</head>
<body>
    <div class="container">
    <div class="f" style="height:100px">
        A
    </div>
    <div class="f" style="height:150px">
        B
    </div>
    <div class="f" style="height:200px">
        C
    </div>
    <div class="f" style="height:50px">
        D
    </div>
    </div>
</body>
</html>

1.用浏览器打开上面的html,它看起来像这样 enter image description here

2.将C的高度降低到120px

现在看起来像这样 enter image description here

根据规范:

If the current box is left-floating, and there are any left-floating boxes generated by elements earlier in the source document, then for each such earlier box, either the left outer edge of the current box must be to the right of the right outer edge of the earlier box, or its top must be lower than the bottom of the earlier box. Analogous rules hold for right-floating boxes.

D 的顶部必须低于前面盒子(A,B,C)的底部 但是现在 D 的顶部比 B 高。为什么?

最佳答案

它说两者中的任何一个都是真的。

either the left outer edge of the current box must be to the right of the right outer edge of the earlier box,

or its top must be lower than the bottom of the earlier box.

对于 D,条件 1 对于 B 为真,条件 2 对于 C 为真

关于css - 与 float 行为混淆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22446935/

相关文章:

css - ionic 滑动盒中的 100% 高度不起作用

html 的 jQuery 移动结构

html - Safari 中未应用最大高度

html - 有没有办法重复CSS Sprite 工作中的特定像素

javascript - 向动态生成的按钮添加和删除事件类事件监听器

css - 如何从某个断点将固定布局变成流动布局?

javascript - 如何防止人们使用鼠标滚轮滚动按下我们的触摸拖动?

html - 如何将嵌套的 div 放置在底部并向右浮动?

javascript - 加载插件后如何覆盖图标类?

php - POST 表单显示错误回显