This is not possible with CSS - it's a styling language, not a programming language and doesn't have the capacity to 'run' any code. However, it is relatively straightforward with JS. I originally misread the selector as just 4
, not 4n
, which makes things a little more involved:
const listItems = document.querySelectorAll('.gallery > .gallery_list > li');
const separator = Math.ceil(Math.random() * 4);
listItems.forEach((item, i) => {
if ((i + 1) % separator === 0) {
item.classList.add('span-3');
}
});
.span-3 {
grid-column: span 3;
grid-row: span 3;
color: red;
}
<div class="gallery">
<ul class="gallery_list">
<li>Item One</li>
<li>Item Two</li>
<li>Item Three</li>
<li>Item Four</li>
<li>Item Five</li>
<li>Item Six</li>
<li>Item Seven</li>
<li>Item Eight</li>
<li>Item Nine</li>
<li>Item Ten</li>
</ul>
</div>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…