I have a responsive grid layout, the columns and rows are calculated dynamically by the window's size.
Now I want the .target to be on a specific cell regardless of the grid columns, let's say the 7th cell, so if the grid has 5 columns, the .target should be on the row 2 and column 2. Is this possible to do it?
I know I can use grid-row and grid-column to assign the position of an element. But the grid rows and columns are dynamic, so I wouldn't know which row and column is the 7th cell.
.grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
grid-auto-rows: 100px;
width: 100%;
}
/* this need to be on the 7th cell */
.target {
background-color: red;
}
<div class="grid">
<span class="target"></span>
</div>
I could create a lot of empty elements to push the .target on to the 7th cell, but I'm not allowed to touch the html structure so I can't do this:
.grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
grid-auto-rows: 100px;
width: 100%;
}
.target {
background-color: red;
}
<div class="grid">
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span class="target"></span>
</div>