HTML 网格单元格,具有行起始和跨行直到网格结束。

huangapple go评论69阅读模式
英文:

HTML Grid Cell with Row Start and Row Span til the end of the grid

问题

I have this grid layout:

HTML 网格单元格,具有行起始和跨行直到网格结束。

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:

HTML 网格单元格,具有行起始和跨行直到网格结束。

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


&lt;div class=&quot;grid grid-cols-5 auto-rows-auto gap-4&quot;&gt;
    &lt;div class=&quot;col-start-2&quot;&gt;2&lt;/div&gt;
    &lt;div class=&quot;col-start-3&quot;&gt;3&lt;/div&gt;
    &lt;div class=&quot;col-start-4&quot;&gt;4&lt;/div&gt;
    &lt;div class=&quot;row-start-2&quot;&gt;5&lt;/div&gt;
    &lt;div class=&quot;col-start-1 row-start-3&quot;&gt;6&lt;/div&gt;
    &lt;div class=&quot;col-start-1 row-start-4&quot;&gt;7&lt;/div&gt;
    &lt;div class=&quot;col-start-1 row-start-5&quot;&gt;8&lt;/div&gt;
    &lt;div class=&quot;col-span-4 col-start-2 row-start-2 [missing class to take up the rest of the row]&quot;&gt;9&lt;/div&gt;
&lt;/div&gt;
    

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(&gt;*)) {
  background-color: aquamarine;
  text-align: center;
}

<!-- language: lang-html -->

&lt;script src=&quot;https://cdn.tailwindcss.com&quot;&gt;&lt;/script&gt;
&lt;div class=&quot;grid grid-cols-5 auto-rows-auto gap-4&quot;&gt;
  &lt;div class=&quot;col-start-2&quot;&gt;2&lt;/div&gt;
  &lt;div class=&quot;&quot;&gt;3&lt;/div&gt;
  &lt;div class=&quot;&quot;&gt;4&lt;/div&gt;
  &lt;div class=&quot;side-bar col-start-1 row-start-2 grid grid-cols-1 auto-rows-auto gap-4&quot;&gt;
    &lt;div&gt;5&lt;/div&gt;
    &lt;div&gt;6&lt;/div&gt;
    &lt;div&gt;7&lt;/div&gt;
    &lt;div&gt;8&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class=&quot; col-start-2 col-span-4 row-start-2&quot;&gt;9&lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年6月26日 17:19:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76555296.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定