grid-cols. are not evenly spaced 栅格列未均匀间隔

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

grid-cols. are not evenly spaced

问题

I am using Tailwind and. I am trying to create a three column div. Two divs are relatively close to each other, and the last one is on the end.

我正在使用Tailwind,尝试创建一个包含三列的div。前两个div相对靠近,最后一个在最右边。

Something like this

类似这样

What I currently have is

我目前的代码如下:

<a href="https://www.google.com/" class="flex w-3/4 h-32 bg-blue-50 items-center hover:bg-blue-100" v-for="video in content.videos">
<div class="grid grid-cols-3 gap-5 p-2 bg-gray-200 max-w-md">
<div class="pt-2 col-span-1">
<img src="../../assets/video-md.svg" alt="tutorial" />
</div>
<div class="text-center col-span-2">
<span class="text-2xl pb-5"> {{ video.title }} </span>
<br />
<div class="w-15">
{{ video.paid ? 'Free Resource' : 'Paid Resource' }}
</div>
<div class="text-sm justify-end">
<span> {{ video.length }}</span>
</div>
</div>
</div>
</a>

I tried to use different col-span tags with no avail.

我尝试使用不同的col-span标签,但没有成功。

Advice?

有建议吗?

---- update 1 ----

更新1:

grid-cols. are not evenly spaced
栅格列未均匀间隔

From this code provided in an answer.

从答案中提供的这段代码中:

<div class="bg-white-200" v-for="c in courseContents">
<div class="flex flex-col items-center gap-2" v-for="content in c.contents">
<span class="text-black text-2xl">
{{ content.sectionTitle }}
</span>
<a href="https://www.google.com/" class="flex w-3/4 h-32 bg-blue-50 items-center hover:bg-blue-100" v-for="video in content.videos">
<div class="grid grid-cols-[max-content_1fr_max-content] gap-5 p-2 bg-gray-200 max-w-md w-full">
<div class="pt-2">
<img src="../../assets/video-md.svg" alt="tutorial" />
</div>
<div>
<span class="text-2xl pb-5"> {{ video.title }} </span>
<br />
{{ video.paid ? 'Free Resource' : 'Paid Resource' }}
</div>
<div class="text-sm self-end">
<span> {{ video.length }} </span>
</div>
</div>
</a>
</div>
</div>

For some reason the last col will not move to the far right.

由于某种原因,最后一列不会移到最右边。

英文:

I am using Tailwind and. I am trying to create a three column div. Two divs are relatively close to each other, andgrid-cols. are not evenly spaced
栅格列未均匀间隔 the last one is on the end.

Something like this

What I currently have is

grid-cols. are not evenly spaced
栅格列未均匀间隔

            &lt;a href=&quot;https://www.google.com/&quot; class=&quot;flex w-3/4 h-32 bg-blue-50 items-center hover:bg-blue-100&quot; v-for=&quot;video in content.videos&quot;&gt;
                &lt;div class=&quot;grid grid-cols-3 gap-5 p-2 bg-gray-200 max-w-md&quot;&gt;
                    &lt;div class=&quot;pt-2 col-span-1&quot;&gt;
                        &lt;img src=&quot;../../assets/video-md.svg&quot;  alt=&quot;tutorial&quot; /&gt;
                    &lt;/div&gt;
                    &lt;div class=&quot;text-center col-span-2&quot;&gt;
                        &lt;span class=&quot;text-2xl pb-5&quot;&gt; {{ video.title }} &lt;/span&gt;
                        &lt;br /&gt;
                        &lt;div class=&quot;w-15&quot;&gt;
                            {{ video.paid ? &#39;Free Resource&#39; : &#39;Paid Resource&#39; }}
                        &lt;/div&gt;
                        &lt;div class=&quot;text-sm justify-end&quot;&gt;
                            &lt;span&gt; {{ video.length }}&lt;/span&gt;
                        &lt;/div&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
            &lt;/a&gt;

I tried to use different col-span. tags with no avail.

Advice?

---- update 1 ----

I now have

grid-cols. are not evenly spaced
栅格列未均匀间隔

From this code provided in an answer.

&lt;div class=&quot;bg-white-200&quot; v-for=&quot;c in courseContents&quot;&gt;
        &lt;div class=&quot;flex flex-col items-center gap-2&quot; v-for=&quot;content in c.contents&quot;&gt;
                &lt;span class=&quot;text-black text-2xl&quot;&gt;
                    {{ content.sectionTitle }}
                &lt;/span&gt;
            &lt;a href=&quot;https://www.google.com/&quot; class=&quot;flex w-3/4 h-32 bg-blue-50 items-center hover:bg-blue-100&quot; v-for=&quot;video in content.videos&quot;&gt;
                &lt;div class=&quot;grid grid-cols-[max-content_1fr_max-content] gap-5 p-2 bg-gray-200 max-w-md w-full&quot;&gt;
                    &lt;div class=&quot;pt-2&quot;&gt;
                        &lt;img src=&quot;../../assets/video-md.svg&quot; alt=&quot;tutorial&quot; /&gt;
                    &lt;/div&gt;
                    &lt;div&gt;
                        &lt;span class=&quot;text-2xl pb-5&quot;&gt; {{ video.title }} &lt;/span&gt;
                        &lt;br /&gt;
                        {{ video.paid ? &#39;Free Resource&#39; : &#39;Paid Resource&#39; }}
                    &lt;/div&gt;
                    &lt;div class=&quot;text-sm self-end&quot;&gt;
                        &lt;span&gt; {{ video.length }} &lt;/span&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
            &lt;/a&gt;
        &lt;/div&gt;
    &lt;/div&gt;

For some reason the last col will not move to the far right.

答案1

得分: 1

如果您想要从图像中表示的布局,对我来说似乎是一个两列布局 - 一个用于图像的“静态”列,然后另一个用于文本的列。免费资源一分钟 的文本看起来占据了相同的y轴,因此它们似乎在同一行内:

<!-- begin snippet: js hide: false console: false babel: false -->

<!-- language: lang-html -->
    <script src="https://cdn.tailwindcss.com"></script>

    <a href="https://www.google.com/" class="flex w-3/4 h-32 bg-blue-50 items-center hover:bg-blue-100" v-for="video in content.videos">
      <div class="grid grid-cols-[max-content_1fr] gap-5 p-2 bg-gray-200 max-w-md w-full">
        <div class="pt-2">
          <img src="https://picsum.photos/48/48" alt="tutorial" />
        </div>
        <div>
          <span class="text-2xl pb-5"> {{ video.title }} </span>
          <br />
          <div class="w-15 flex justify-between items-baseline">
            <span>Free Resource</span>
            <span class="text-sm"> {{ video.length }}</span>
          </div>
        </div>
      </div>
    </a>

<!-- end snippet -->

否则,如果您想要三列,您可以将 {{ video.length }} 与其余文本分开:

<!-- begin snippet: js hide: false console: false babel: false -->

<!-- language: lang-html -->
    <script src="https://cdn.tailwindcss.com"></script>

    <a href="https://www.google.com/" class="flex w-3/4 h-32 bg-blue-50 items-center hover:bg-blue-100" v-for="video in content.videos">
      <div class="grid grid-cols-[max-content_1fr_max-content] gap-5 p-2 bg-gray-200 max-w-md w-full">
        <div class="pt-2">
          <img src="https://picsum.photos/48/48" alt="tutorial" />
        </div>
        <div>
          <span class="text-2xl pb-5"> {{ video.title }} </span>
          <br />
          Free Resource
        </div>
        <div class="text-sm self-end">
          <span> {{ video.length }}</span>
        </div>
      </div>
    </a>

<!-- end snippet -->

或者使用内部网格:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->
    <script src="https://cdn.tailwindcss.com"></script>

    <a href="https://www.google.com/" class="flex w-3/4 h-32 bg-blue-50 items-center hover:bg-blue-100" v-for="video in content.videos">
      <div class="grid grid-cols-[max-content_repeat(2,1fr)] gap-5 p-2 bg-gray-200 max-w-md w-full">
        <div class="pt-2">
          <img src="https://picsum.photos/48/48" alt="tutorial" />
        </div>
        <div class="col-span-2 grid grid-cols-[1fr_max-content]">
          <div>
            <span class="text-2xl pb-5"> {{ video.title }} </span>
            <br/>
            Free Resource
          </div>
          <div class="text-sm self-end">
            <span> {{ video.length }}</span>
          </div>
        </div>
      </div>
    </a>

<!-- end snippet -->
英文:

If you want the layout represented from the image, it seems like to me a two column layout – one "static" one for the image and then another one for the text. The Free Resource and a minute text look like they occupy the same y-axis so it would seem like they would in the same row:

<!-- begin snippet: js hide: false console: false babel: false -->

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

&lt;script src=&quot;https://cdn.tailwindcss.com&quot;&gt;&lt;/script&gt;

&lt;a href=&quot;https://www.google.com/&quot; class=&quot;flex w-3/4 h-32 bg-blue-50 items-center hover:bg-blue-100&quot; v-for=&quot;video in content.videos&quot;&gt;
  &lt;div class=&quot;grid grid-cols-[max-content_1fr] gap-5 p-2 bg-gray-200 max-w-md w-full&quot;&gt;
    &lt;div class=&quot;pt-2&quot;&gt;
      &lt;img src=&quot;https://picsum.photos/48/48&quot; alt=&quot;tutorial&quot; /&gt;
    &lt;/div&gt;
    &lt;div&gt;
      &lt;span class=&quot;text-2xl pb-5&quot;&gt; {{ video.title }} &lt;/span&gt;
      &lt;br /&gt;
      &lt;div class=&quot;w-15 flex justify-between items-baseline&quot;&gt;
        &lt;span&gt;Free Resource&lt;/span&gt;
        &lt;span class=&quot;text-sm&quot;&gt; {{ video.length }}&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/a&gt;

<!-- end snippet -->

Otherwise if you did want three columns, you could separate out the {{ video.length }} from the rest of the text:

<!-- begin snippet: js hide: false console: false babel: false -->

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

&lt;script src=&quot;https://cdn.tailwindcss.com&quot;&gt;&lt;/script&gt;

&lt;a href=&quot;https://www.google.com/&quot; class=&quot;flex w-3/4 h-32 bg-blue-50 items-center hover:bg-blue-100&quot; v-for=&quot;video in content.videos&quot;&gt;
  &lt;div class=&quot;grid grid-cols-[max-content_1fr_max-content] gap-5 p-2 bg-gray-200 max-w-md w-full&quot;&gt;
    &lt;div class=&quot;pt-2&quot;&gt;
      &lt;img src=&quot;https://picsum.photos/48/48&quot; alt=&quot;tutorial&quot; /&gt;
    &lt;/div&gt;
    &lt;div&gt;
      &lt;span class=&quot;text-2xl pb-5&quot;&gt; {{ video.title }} &lt;/span&gt;
      &lt;br /&gt;
      Free Resource
    &lt;/div&gt;
    &lt;div class=&quot;text-sm self-end&quot;&gt;
      &lt;span&gt; {{ video.length }}&lt;/span&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/a&gt;

<!-- end snippet -->

Or have an inner grid:

<!-- begin snippet: js hide: false console: true babel: false -->

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

&lt;script src=&quot;https://cdn.tailwindcss.com&quot;&gt;&lt;/script&gt;

&lt;a href=&quot;https://www.google.com/&quot; class=&quot;flex w-3/4 h-32 bg-blue-50 items-center hover:bg-blue-100&quot; v-for=&quot;video in content.videos&quot;&gt;
  &lt;div class=&quot;grid grid-cols-[max-content_repeat(2,1fr)] gap-5 p-2 bg-gray-200 max-w-md w-full&quot;&gt;
    &lt;div class=&quot;pt-2&quot;&gt;
      &lt;img src=&quot;https://picsum.photos/48/48&quot; alt=&quot;tutorial&quot; /&gt;
    &lt;/div&gt;
    &lt;div class=&quot;col-span-2 grid grid-cols-[1fr_max-content]&quot;&gt;
      &lt;div&gt;
        &lt;span class=&quot;text-2xl pb-5&quot;&gt; {{ video.title }} &lt;/span&gt;
        &lt;br/&gt;
        Free Resource
      &lt;/div&gt;
      &lt;div class=&quot;text-sm self-end&quot;&gt;
        &lt;span&gt; {{ video.length }}&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/a&gt;

<!-- end snippet -->

答案2

得分: 1

  • max-w-md导致宽度有限,这就是为什么“一分钟”文本不会出现在右侧。请删除它。
  • 三个列没有垂直居中对齐,所以请在grid grid-cols-.... div中添加items-center

我已经在纠正一些错误后添加了以下代码。

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->
<script src="https://cdn.tailwindcss.com"></script>

<div class="bg-white-200" v-for="c in courseContents">
    <div class="flex flex-col items-center gap-2" v-for="content in c.contents">
        <span class="text-black text-2xl">
            Magnus Effect
        </span>
        <a href="https://www.google.com/" class="flex w-3/4 h-32 bg-blue-50 items-center hover:bg-blue-100" v-for="video in content.videos">
            <div class="grid grid-cols-[max-content_1fr_max-content] items-center gap-5 p-2 w-full">
                <div class="pt-2">
                    <img src="http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/asteroid_blue.png" alt="tutorial" />
                </div>
                <div>
                    <span class="text-2xl pb-5"> Tree </span>
                    <br />
                    Free Resource
                </div>
                <div class="text-sm self-end">
                    <span> 12 min </span>
                </div>
            </div>
        </a>
    </div>
</div>

<!-- end snippet -->

您也可以将其修改为问题中所示的示例,如下所示:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->
<script src="https://cdn.tailwindcss.com"></script>
<div class="h-screen bg-[#1a202c]" v-for="c in courseContents">
    <div class="flex flex-col items-center gap-2" v-for="content in c.contents">
        <span class="my-10 text-2xl text-white"> Scroll Down to see </span>
        <a href="https://www.google.com/" class="flex h-32 w-3/4 items-center rounded-lg bg-[#2d3748] hover:bg-[#2d3748]/70" v-for="video in content.videos">
            <div class="grid w-full grid-cols-[max-content_1fr_max-content] items-center gap-5 p-2 text-white">
                <div class="pt-2">
                    <img src="http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/asteroid_blue.png" alt="tutorial" />
                </div>
                <div>
                    <span class="pb-5 text-2xl"> Tree </span>
                    <br />
                    <span class="text-white/75">Free Resource</span>
                </div>
                <div class="mr-4 self-end text-sm">
                    <span> 12 min </span>
                </div>
            </div>
        </a>
    </div>
</div>

<!-- end snippet -->
英文:

I have noticed some mistakes in your code.

  • max-w-md is causing limited width , that's why a minute text is not appearing on the right side. Remove it.
  • The three columns are not centered vertically , so please add items-center in the grid grid-cols-.... div.

I have added below code after correcting some mistakes.

<!-- begin snippet: js hide: false console: true babel: false -->

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

<script src="https://cdn.tailwindcss.com"></script>

&lt;div class=&quot;bg-white-200&quot; v-for=&quot;c in courseContents&quot;&gt;
        &lt;div class=&quot;flex flex-col items-center gap-2&quot; v-for=&quot;content in c.contents&quot;&gt;
                &lt;span class=&quot;text-black text-2xl&quot;&gt;
                    Magnus Effect
                &lt;/span&gt;
            &lt;a href=&quot;https://www.google.com/&quot; class=&quot;flex w-3/4 h-32 bg-blue-50 items-center hover:bg-blue-100&quot; v-for=&quot;video in content.videos&quot;&gt;
                &lt;div class=&quot;grid grid-cols-[max-content_1fr_max-content] items-center gap-5 p-2  w-full&quot;&gt;
                    &lt;div class=&quot;pt-2&quot;&gt;
                        &lt;img src=&quot;http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/asteroid_blue.png&quot; alt=&quot;tutorial&quot; /&gt;
                    &lt;/div&gt;
                    &lt;div&gt;
                        &lt;span class=&quot;text-2xl pb-5&quot;&gt; Tree &lt;/span&gt;
                        &lt;br /&gt;
                        Free Resource
                    &lt;/div&gt;
                    &lt;div class=&quot;text-sm self-end&quot;&gt;
                        &lt;span&gt; 12 min &lt;/span&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
            &lt;/a&gt;
            
        &lt;/div&gt;
    &lt;/div&gt;

<!-- end snippet -->

Also you can modify it to the example that you've shown in the question like this

<!-- begin snippet: js hide: false console: true babel: false -->

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

&lt;script src=&quot;https://cdn.tailwindcss.com&quot;&gt;&lt;/script&gt;
&lt;div class=&quot;h-screen bg-[#1a202c]&quot; v-for=&quot;c in courseContents&quot;&gt;
  &lt;div class=&quot;flex flex-col items-center gap-2&quot; v-for=&quot;content in c.contents&quot;&gt;
    &lt;span class=&quot;my-10 text-2xl text-white&quot;&gt; Scroll Down to see &lt;/span&gt;
    &lt;a href=&quot;https://www.google.com/&quot; class=&quot;flex h-32 w-3/4 items-center rounded-lg bg-[#2d3748] hover:bg-[#2d3748]/70&quot; v-for=&quot;video in content.videos&quot;&gt;
      &lt;div class=&quot;grid w-full grid-cols-[max-content_1fr_max-content] items-center gap-5 p-2 text-white&quot;&gt;
        &lt;div class=&quot;pt-2&quot;&gt;
          &lt;img src=&quot;http://commondatastorage.googleapis.com/codeskulptor-assets/lathrop/asteroid_blue.png&quot; alt=&quot;tutorial&quot; /&gt;
        &lt;/div&gt;
        &lt;div&gt;
          &lt;span class=&quot;pb-5 text-2xl&quot;&gt; Tree &lt;/span&gt;
          &lt;br /&gt;
          &lt;span class=&quot;text-white/75&quot;&gt;Free Resource&lt;/span&gt;
        &lt;/div&gt;
        &lt;div class=&quot;mr-4 self-end text-sm&quot;&gt;
          &lt;span&gt; 12 min &lt;/span&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/a&gt;
  &lt;/div&gt;
&lt;/div&gt;

<!-- end snippet -->

huangapple
  • 本文由 发表于 2023年6月12日 15:13:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/76454326.html
匿名

发表评论

匿名网友

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

确定