我尝试使用 FlexBox,
.spotlight-wrapper {
width: 100%;
overflow-x: auto;
}
.spotlight-wrapper .spotlight {
list-style: none;
height: 230px;
display: flex;
flex-direction: column;
flex-wrap: wrap;
justify-content: bottom;
padding: 0;
}
.spotlight-wrapper .spotlight li {
width: 220px;
height: 220px;
background: #ccc;
margin: 5px;
}
.spotlight-wrapper .spotlight li.small {
width: 105px;
height: 105px;
}
.spotlight-wrapper .spotlight li.medium {
width: 220px;
height: 105px;
/*
* Idea to fix it, but will cause
* issue if the medium tile in the
* bottom level, and there are 2 small
* tiles next to it in the top level
*/
/* & + .small + .small{
display: block;
clear: both;
justify-content: bottom;
margin-top: 120px;
margin-left: -110px;
} */
}
.spotlight-wrapper .spotlight li.red {
background: red;
}
<div class="spotlight-wrapper">
<ul class="spotlight">
<li>Tile #1</li>
<li class="small">Tile #2</li>
<li class="small">Tile #3</li>
<li class="medium">Tile #9</li>
<li class="medium">Tile #10</li>
<li>Tile #2</li>
<li class="medium red">Tile #1</li>
<li class="small red">Tile #2</li>
<li class="small red">Tile #3</li>
<li>Tile #5</li>
<li>Tile #7</li>
<li>Tile #8</li>
<li class="medium">Tile #9</li>
<li class="medium">Tile #10</li>
<li>Tile #11</li>
<li>Tile #12</li>
<li class="small">Tile #13</li>
<li>Tile #14</li>
<li>Tile #15</li>
<li>Tile #16</li>
<li>Tile #17</li>
<li>Tile #18</li>
<li>Tile #19</li>
<li>Tile #20</li>
</ul>
但是,如果您检查红色瓷砖,它的对齐方式不正确,我可以使用边距修复它(检查注释块)但如果宽瓷砖位于底行,并且有 2 个小瓷砖在下一个街区,
此外,如果只有一小块瓷砖,则会创建空白空间。