Unknown width for variable number of columns
P粉441076405
P粉441076405 2023-08-20 21:40:19
0
1
548

I want to arrange some items in a column. I can't predict the width or height of the item, nor the width or height of the container. I also can't predict how many columns will fit or what the width of the columns should be. I want the browser to arrange the items in the maximum number of columns without exceeding the width of the container, while minimizing the height of the container.

This solved the problem, but is there a better way? Can this be achieved without using jQuery? Can it be done in a way that older browsers will display it properly (perhaps by arranging it in rows instead of columns)?

 
1
2
3
4
5
6
7
8
9


P粉441076405
P粉441076405

reply all (1)
P粉865900994

You can use a grid to achieve this

#wrapper { display: grid; grid-auto-flow: row; grid-gap: 20px; grid-template-columns: repeat(9, 1fr); //将9更改为列数 }
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!