How to use flex layout to solve the problem shown in the figure?

now has the following html structure, the number of li tags is unknown and variable, you need to use the ul tag display: flex to layout, the page effect is shown in the figure.
effect description:
figure 1. What to do when there are not enough li tags?
figure 2. What should I do when the distance of the li tag is greater than the width of the li tag?

<ul>
    <li></li>
    ...
    <li></li>
<ul>

Jun.18,2022

flex reference https://codeshelper.com/a/11...

use space-between

When

li is not enough, the li added
hides the opacity:0 or visibility:hidden with a special class


this you can refer to teacher Ruan Yifeng's flex layout

actually, I don't know what you're trying to say here:

  1. li tag is not enough, this is variable, this is uncontrollable, he has several display, for example, if you want three per line, you can set the size of the li, and then the extra li tags wrap.
ul {
  display: flex;
  flex-wrap: wrap; //
}

2. I think what you mean is that the spacing is too big to look good. You can set all these by yourself, such as setting the first margin-left and the third margin-right. Adjust the layout yourself. Then through the energy: nth:child () to set 1, 4, 4, 7. Margin-left, and margin-right

of 3Jet 6 and 9.
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-1b32dfa-2be56.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-1b32dfa-2be56.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?