This is a CSS grid question, I have a list of elements displayed as a grid. I would like to place the elements with a class of picture-folder in the first column (cell) of every row.
Expected output would be as followed:
picture folder | picture item | picture item | picture item
picture folder | picture item | picture item | picture item
picture folder | picture item | picture item | picture item
empty | picture item | picture item | picture item
empty | picture item | picture item | picture item
empty | picture item | picture item | picture item
empty | picture item | picture item | picture item
I have the following HTML (We can have more or less elements)
<ul class="grid responsive__grid no__bullet p__0 picture-list">
<li class="picture_item">
<img class="picture_preview" src="1.jpg">
<div class="picture-name">login_splash_screen.jpg</div>
</li>
<li class="picture_item">
<img class="picture_preview" src="2.jpg">
<div class="picture-name">la-belle-escola-banner.jpg</div>
</li>
<li class="picture_item picture-folder">
<a href="/fr/cms/pictures?prefix=intranet"><img alt="folder" class="icon-image folder-icon" src="/assets/mdi/folder.svg" title="folder"></a>
<a class="picture-name" href="/fr/cms/pictures?prefix=intranet">intranet</a>
<div class="pic">Un fichier</div>
<div class="pic">25,278 Ko</div>
</li>
<li class="picture_item">
<img class="picture_preview" src="3.jpg">
<div class="picture-name">la-belle-escola-banner.jpg</div>
</li>
<li class="picture_item">
<img class="picture_preview" src="3.jpg">
<div class="picture-name">la-belle-escola-banner.jpg</div>
</li>
<li class="picture_item">
<img class="picture_preview" src="3.jpg">
<div class="picture-name">la-belle-escola-banner.jpg</div>
</li>
<li class="picture_item">
<img class="picture_preview" src="3.jpg">
<div class="picture-name">la-belle-escola-banner.jpg</div>
</li>
<li class="picture_item">
<img class="picture_preview" src="3.jpg">
<div class="picture-name">la-belle-escola-banner.jpg</div>
</li>
<li class="picture_item">
<img class="picture_preview" src="3.jpg">
<div class="picture-name">la-belle-escola-banner.jpg</div>
</li>
<li class="picture_item picture-folder">
<a href="/fr/cms/pictures?prefix=intranet"><img alt="folder" class="icon-image folder-icon" src="/assets/mdi/folder.svg" title="folder"></a>
<a class="picture-name" href="/fr/cms/pictures?prefix=intranet">intranet</a>
<div class="pic">Un fichier</div>
<div class="pic">25,278 Ko</div>
</li>
<li class="picture_item picture-folder">
<a href="/fr/cms/pictures?prefix=intranet"><img alt="folder" class="icon-image folder-icon" src="/assets/mdi/folder.svg" title="folder"></a>
<a class="picture-name" href="/fr/cms/pictures?prefix=intranet">intranet</a>
<div class="pic">Un fichier</div>
<div class="pic">25,278 Ko</div>
</li>
<li class="picture_item picture-folder">
<a href="/fr/cms/pictures?prefix=intranet"><img alt="folder" class="icon-image folder-icon" src="/assets/mdi/folder.svg" title="folder"></a>
<a class="picture-name" href="/fr/cms/pictures?prefix=intranet">intranet</a>
<div class="pic">Un fichier</div>
<div class="pic">25,278 Ko</div>
</li>
</ul>
My CSS so far
.grid
{
display: grid;
gap: 1rem;
.responsive__grid
{
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}
I tried using .picture-folder{grid-column-start:1;grid-row-start:1;}
but all the picture-folder items overlap each other
2
Answers
Use
grid-auto-flow: column
and then put the elements ingrid-column: 1
You may also use
order
asidegrid-column
selecting the.picture-folder
classTo clear the first-column , you may use a pseudo element spanning many rows, that becomes a trick, javascript would be useful to set the number of rows to clear