为什么input会出来?

为什么当给.father不添加浮动时,input不在.father的盒子里,而是紧贴着.mother在其下一行?(指y轴方向上的下方)


<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .mother {
            float: left;
            width: 400px;
            height: 200px;
            background-color: pink;
        }
        .father {
            /*float: left;*/
            width: 200px;
            height: 100px;
            background-color: skyblue;
        }
    </style>
</head>

<body>
    <div class="mother"></div>
    <div class="father">
        <input  type="text" style="background-color: yellow;">
    </div>
</body>

</html>

img

div是块元素 你给第一个div 加了 float 但是第二个没加啊 ,所以才会在下面,如有帮助给个采纳,下个问题不迷路谢谢

因为div自身本就是会换行的,加了浮动后会在父盒子内紧挨着相邻的盒子左右排列(空间不够也会换行)

应该BFC特性(块级格式化上下文),BFC不会影响其它BFC中的元素,这里float: left创建了一个BFC,inputinline-block也是BFC,所以没有影响。具体可以搜下BFC了解。