HTML div learning record 2

As mentioned in the previous blog post, the child div of float cannot support the height of the parent div. In fact, this sentence is flawed! To be precise: the child div of float is separated from the flow of the parent div ,

<html>
<head></head>
<body>
    <div>
        <div style="float:left">qwqeqwoe最外层的div 的width为1294px, height为0, 分析如下: 
里面的子div使用float后导致上面的结果,可见当里面的子div使用float后,子div的宽度不是显示为浏览器的宽度,而是由div里面的内容决定,不会占用一行,第二个使用了float的子div不会显示为新的一行,第三个没有使用float的子div把前面两个同级的div看做透明的一ewrvsffffffffffffffffffffffffffffffffffffffcccccccccccccccccccccccccccccccvbdfbbbbbdsqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqfref4444444555555555555555555555555555555555555555555555555555555555555555552311111111111111111111777777777777</div>
        <div>输入 netstat -ano|findstr “8080” 找到占用该端口的进程PID ,本机为 3864输入 tasklist|findstr 3864 获取占用程序名称,我的电脑为ApplicationWebServertaskkill /f /t /im ApplicationWebServer.exe 还有一种简便方法就是: 
在执行上面1所述的步骤后,输入taskkill /F /PID 3864 ,这样就可以解决端口被占用的问题</div>

    <div>
</body>
</html>

write picture description here

In browser debugging mode, check the width and height of the sibling div without float (in the example, the first two divs already have the float attribute), and find that the unfloated div is the same height as the parent div , and the first two divs have the same height as the parent div. The height of the brother div dropped by the float is counted! , So the floating div still increases the height of the father div , but from the picture below, as shown in the
figure below , this non-floating div takes advantage, and the credit is all alone!

write picture description here

Note
The above example is an extreme example, which means turning the corner . Generally speaking, it is best to set the width of floating div or other elements. If there is a lot of content, you need to set word-break or word-wrap through css. make a newline

Summary:
1. In terms of div layout: the div should be written from the bottom up, do not consider the parent div first, angle: put these contents, you should use a div

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325655781&siteId=291194637