174. CSS Grid Layout auto-placement algorithm - sparse
Are you familiar with CSS Grid Layout ?
grid-auto-flow controls how the auto-placement algorithm works.
Default packing mode is sparse
, please create a function to illustrate how it works.
1 |
|
- it should return a grid of item id, use 0 if the cell is no occupied.
- implement the logic based on
grid-auto-flow: row
. - all inputs are valid, in which there is no overlapping between the items, and all items stay fully inside of the grid.
- you can refer to the office algorithm explanation
Here are some examples you can understand it better.
1 |
|
In the above example, all items are auto placed.
1 |
|
Now in above example first two items have more specific positions.
174. CSS Grid Layout auto-placement algorithm - sparse
http://example.com/2023/04/25/bg-174/