英文:
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:
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, and the last one is on the end.
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.
Advice?
---- update 1 ----
I now have
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.
答案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 -->
<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 -->
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 -->
<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 -->
Or have an inner grid:
<!-- 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 -->
答案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 whya minute
text is not appearing on the right side. Remove it.- The three columns are not centered vertically , so please add
items-center
in thegrid 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>
<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 -->
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 -->
<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 -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论