英文:
HTML Grid Cell with Row Start and Row Span til the end of the grid
问题
I have this grid layout:
The side menu (5, 6, 7, 8) has a dynamic content and can populate to x number of items. I want the main content (9) to span its row based on the size of the side bar.
I am using tailwind, whenever I try to put row-span-full
to cell 9, it overlaps the tabs (2, 3, 4). Meaning to say, it takes up all the rows even though I have indicated the row-start-2
.
Here's my code:
<div class="grid grid-cols-5 auto-rows-auto gap-4">
<div class="col-start-2">2</div>
<div class="col-start-3">3</div>
<div class="col-start-4">4</div>
<div class="row-start-2">5</div>
<div class="col-start-1 row-start-3">6</div>
<div class="col-start-1 row-start-4">7</div>
<div class="col-start-1 row-start-5">8</div>
<div class="col-span-4 col-start-2 row-start-2 [missing class to take up the rest of the row]">9</div>
</div>
Is this achievable in HTML Grid? Because this is very easy with flexbox.
英文:
I have this grid layout:
The side menu (5, 6, 7, 8) has a dynamic content and can populate to x number of items. I want the main content (9) to span it's row based to the size of the side bar.
I am using tailwind, whenever I try to put row-span-full
to the cell 9, it overlaps the tab (2, 3, 4). Meaning to say, It took all the rows even I have indicated the row-start-2
.
Here's my code
<div class="grid grid-cols-5 auto-rows-auto gap-4">
<div class="col-start-2">2</div>
<div class="col-start-3">3</div>
<div class="col-start-4">4</div>
<div class="row-start-2">5</div>
<div class="col-start-1 row-start-3">6</div>
<div class="col-start-1 row-start-4">7</div>
<div class="col-start-1 row-start-5">8</div>
<div class="col-span-4 col-start-2 row-start-2 [missing class to take up the rest of the row]">9</div>
</div>
Is this achievable in HTML Grid? Because this is very easy with flexbox.
答案1
得分: 1
这是CSS Grid本身的限制,而不是Tailwind的问题。以下是一个解决方法:
.grid {
background-color: darkblue;
}
.grid div:not(:has(> *)) {
background-color: aquamarine;
text-align: center;
}
<script src="https://cdn.tailwindcss.com"></script>
<div class="grid grid-cols-5 auto-rows-auto gap-4">
<div class="col-start-2">2</div>
<div class=""></div>
<div class=""></div>
<div class="side-bar col-start-1 row-start-2 grid grid-cols-1 auto-rows-auto gap-4">
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
</div>
<div class="col-start-2 col-span-4 row-start-2">9</div>
</div>
英文:
It's a limitation of CSS Grid itself, not Tailwind's fault. Here's one workaround:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
.grid {
background-color: darkblue;
}
.grid div:not(:has(>*)) {
background-color: aquamarine;
text-align: center;
}
<!-- language: lang-html -->
<script src="https://cdn.tailwindcss.com"></script>
<div class="grid grid-cols-5 auto-rows-auto gap-4">
<div class="col-start-2">2</div>
<div class="">3</div>
<div class="">4</div>
<div class="side-bar col-start-1 row-start-2 grid grid-cols-1 auto-rows-auto gap-4">
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
</div>
<div class=" col-start-2 col-span-4 row-start-2">9</div>
</div>
<!-- end snippet -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论