英文:
How to make 3 row in 1 row on tailwind
问题
我想使用Tailwind CSS将卡片分成3部分。如何实现?
<Card
className="grid grid-rows-2"
>
<h5 className="font-bold tracking-tight text-gray-900 row-span-3">{productName}</h5>
<p className="text-gray-900 text-sm row-span-4">{shortDesc}</p>
<div className="flex items-center justify-between mb-2 row-span-1">
<span className="font-bold text-gray-900">
<Price priceWithTax={priceWithTax} currencyCode={currencyCode} />
</span>
</div>
</Card>
英文:
I want to divide the card into 3 with tailwind css.
how can ı make ?
<Card
className="grid grid-rows-2"
>
<h5 className="font-bold tracking-tight text-gray-900 row-span-3">{productName}</h5>
<p className="text-gray-900 text-sm row-span-4">{shortDesc}</p>
<div className="flex items-center justify-between mb-2 row-span-1">
<span className="font-bold text-gray-900"><Price priceWithTax={priceWithTax} currencyCode={currencyCode} /></span>
</div>
</Card>
答案1
得分: 0
如果您需要三个等大小的列,您可以使用具有列的网格:
<Card className="grid grid-cols-3">
<h5 className="font-bold tracking-tight text-gray-900 row-span-3">{productName}</h5>
<p className="text-gray-900 text-sm row-span-4">{shortDesc}</p>
<div className="flex items-center justify-between mb-2 row-span-1">
<span className="font-bold text-gray-900"><Price priceWithTax={priceWithTax} currencyCode={currencyCode} /></span>
</div>
</Card>
然而,如果您希望将其分为三个等大小的行,您可以使用具有行的网格:
<Card className="grid grid-rows-3">
<h5 className="font-bold tracking-tight text-gray-900 row-span-3">{productName}</h5>
<p className="text-gray-900 text-sm row-span-4">{shortDesc}</p>
<div className="flex items-center justify-between mb-2 row-span-1">
<span className="font-bold text-gray-900"><Price priceWithTax={priceWithTax} currencyCode={currencyCode} /></span>
</div>
</Card>
在grid-cols-{num}
和grid-rows-{num}
中的数字是列或行的数量,就像grid-template-rows: repeat({num}, minmax(0, 1fr));
中一样。您可以在这里查看允许的值。
如果您希望每个部分都适应内容的大小,最好使用 flexbox。
英文:
If you need three equally-sized columns, you can use grid with columns:
<Card className="grid grid-cols-3">
<h5 className="font-bold tracking-tight text-gray-900 row-span-3">{productName}</h5>
<p className="text-gray-900 text-sm row-span-4">{shortDesc}</p>
<div className="flex items-center justify-between mb-2 row-span-1">
<span className="font-bold text-gray-900"><Price priceWithTax={priceWithTax} currencyCode={currencyCode} /></span>
</div>
</Card>
However, if you want to divide it in three equally-sized rows, you can use grid with rows:
<Card className="grid grid-rows-3">
<h5 className="font-bold tracking-tight text-gray-900 row-span-3">{productName}</h5>
<p className="text-gray-900 text-sm row-span-4">{shortDesc}</p>
<div className="flex items-center justify-between mb-2 row-span-1">
<span className="font-bold text-gray-900"><Price priceWithTax={priceWithTax} currencyCode={currencyCode} /></span>
</div>
</Card>
The number in grid-cols-{num}
and grid-rows-{num}
is the number of columns or rows, as in grid-template-rows: repeat({num}, minmax(0, 1fr));
. You can see the allowed values here.
If you need each part to conform to the size of the content, you're better off with flexbox instead.
答案2
得分: 0
你可以通过将带有类名 grid grid-cols-3 gap-4
的 div
标签封装起来,创建一个包含 3 张卡片的行。gap-4
会在它们之间添加一些间距。
你可以查看已更正的代码 这里。
以下是代码:
<div className="p-3 grid grid-cols-3 gap-3">
<Card className="bg-slate-300">
<h5 className="font-bold tracking-tight text-gray-900 row-span-3">{productName}</h5>
<p className="text-gray-900 text-sm row-span-4">{shortDesc}</p>
<div className="flex items-center justify-between mb-2 row-span-1">
<span className="font-bold text-gray-900"><Price priceWithTax="{priceWithTax}" currencyCode="{currencyCode}" /></span>
</div>
</Card>
<Card className="bg-slate-300">
<h5 className="font-bold tracking-tight text-gray-900 row-span-3">{productName}</h5>
<p className="text-gray-900 text-sm row-span-4">{shortDesc}</p>
<div className="flex items-center justify-between mb-2 row-span-1">
<span className="font-bold text-gray-900"><Price priceWithTax="{priceWithTax}" currencyCode="{currencyCode}" /></span>
</div>
</Card>
<Card className="bg-slate-300">
<h5 className="font-bold tracking-tight text-gray-900 row-span-3">{productName}</h5>
<p className="text-gray-900 text-sm row-span-4">{shortDesc}</p>
<div className="flex items-center justify-between mb-2 row-span-1">
<span className="font-bold text-gray-900"><Price priceWithTax="{priceWithTax}" currencyCode="{currencyCode}" /></span>
</div>
</Card>
</div>
一些资源 在这里。
英文:
You can create a row of 3 Cards by encapsulating a div with class grid grid-cols-3 gap-4
. gap-4
will gives some spacing between them.
You can view your corrected code here
Below is the code also
<div className="p-3 grid grid-cols-3 gap-3">
<Card className="bg-slate-300">
<h5 className="font-bold tracking-tight text-gray-900 row-span-3">{productName}</h5>
<p className="text-gray-900 text-sm row-span-4">{shortDesc}</p>
<div className="flex items-center justify-between mb-2 row-span-1">
<span className="font-bold text-gray-900"><Price priceWithTax="{priceWithTax}" currencyCode="{currencyCode}" /></span>
</div>
</Card>
<Card className="bg-slate-300">
<h5 className="font-bold tracking-tight text-gray-900 row-span-3">{productName}</h5>
<p className="text-gray-900 text-sm row-span-4">{shortDesc}</p>
<div className="flex items-center justify-between mb-2 row-span-1">
<span className="font-bold text-gray-900"><Price priceWithTax="{priceWithTax}" currencyCode="{currencyCode}" /></span>
</div>
</Card>
<Card className="bg-slate-300">
<h5 className="font-bold tracking-tight text-gray-900 row-span-3">{productName}</h5>
<p className="text-gray-900 text-sm row-span-4">{shortDesc}</p>
<div className="flex items-center justify-between mb-2 row-span-1">
<span className="font-bold text-gray-900"><Price priceWithTax="{priceWithTax}" currencyCode="{currencyCode}" /></span>
</div>
</Card>
</div>
Some resources here
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论