Why is there a blank problem when the height is inconsistent when the float falls?

problem description

float four li, and the fourth li falls when the width is not enough. If the height of the li is the first > the third > the second, the fourth li will fall under the second li and be the same as the third li. Why?

the environmental background of the problems and what methods you have tried

related codes

/ / Please paste the code text below (do not replace the code with pictures)


  <title>Document</title>
  <style>
    * {
      padding: 0;
      margin: 0;
      border: none;
    }
    ul {
      height: 400px;
    }
    li {
      width: 28%;
      float: left;
      border: 1px solid -sharp000;
      box-sizing: border-box;
    }
    /* li:not(:last-child) {
      width: 28%;
    } */
    li:first-child {
      height: 300px;
    }
    li:nth-child(2) {
      height: 250px;
    }

    li:nth-child(3) {
      height: 270px;
    }
    li:nth-child(4) {
      height: 200px;
    }
  </style>
</head>
<body>
  <ul>
    <li>11</li>
    <li>22</li>
    <li>33</li>
    <li>44</li>
  </ul>
</body>
</html>

what result do you expect? What is the error message actually seen?

Why is this happening

May.18,2022

this needs to explore the floating rules in the css specification.
English rules seem to be difficult, but fortunately, some people interpret adult words and have a Chinese translation.

two of the interpretation rules

  • any floating element appears next to or below the floating element before it. If all elements float to the left, the second element will appear to the right of the first element, and if both float to the right, the second element will appear to the left of the first element.
  • A floating box must be placed as high as possible.
  • A left floating box must be placed as far as possible to the left, and a right floating box should be placed as far as possible to the right. The highest possible position has a higher priority than the left and right.

< del > corresponds to element 4 in your example. It will only be marked with element 3, and it will only appear to the left or bottom of element 3, and its top will follow the bottom of element 3 unless force majeure is encountered. < / del >

corresponds to element 4 in your example, which only aligns with element 3 and appears only to the right or bottom of element 3.
when 3 and 4 are on the same line, 4 will be on the right of 3.
and when 4 is squeezed to the next line, the top of 4 will follow the bottom of 3, unless you encounter float-rules

  • Everything You Never Knew About CSS Floats
  • CSS floats you've never known before | Design Shack

  • 44 normally should start drawing at the lower left corner of 11, but because 11 is too long, it is squeezed below 22. You can try to reduce the height of 11 to the same position as 22 to test. Officially, I forgot because of what? but it seems to be the positioning principle of css.

    MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
    MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bf31df-3a1fc.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
    MySQL Errno : 1021
    Message : Disk full (/tmp/#sql-temptable-64f5-1bf31df-3a1fc.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
    Need Help?