如何在Tailwind中将3行合并为1行

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

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 ?

 &lt;Card
      className=&quot;grid grid-rows-2&quot;
    &gt;
      &lt;h5 className=&quot;font-bold tracking-tight text-gray-900 row-span-3&quot;&gt;{productName}&lt;/h5&gt;
      &lt;p className=&quot;text-gray-900 text-sm row-span-4&quot;&gt;{shortDesc}&lt;/p&gt;
      &lt;div className=&quot;flex items-center justify-between mb-2 row-span-1&quot;&gt;
        &lt;span className=&quot;font-bold text-gray-900&quot;&gt;&lt;Price priceWithTax={priceWithTax} currencyCode={currencyCode} /&gt;&lt;/span&gt;
      &lt;/div&gt;
    &lt;/Card&gt;

答案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:

&lt;Card className=&quot;grid grid-cols-3&quot;&gt;
    &lt;h5 className=&quot;font-bold tracking-tight text-gray-900 row-span-3&quot;&gt;{productName}&lt;/h5&gt;
    &lt;p className=&quot;text-gray-900 text-sm row-span-4&quot;&gt;{shortDesc}&lt;/p&gt;
    &lt;div className=&quot;flex items-center justify-between mb-2 row-span-1&quot;&gt;
        &lt;span className=&quot;font-bold text-gray-900&quot;&gt;&lt;Price priceWithTax={priceWithTax} currencyCode={currencyCode} /&gt;&lt;/span&gt;
    &lt;/div&gt;
&lt;/Card&gt;

However, if you want to divide it in three equally-sized rows, you can use grid with rows:

&lt;Card className=&quot;grid grid-rows-3&quot;&gt;
    &lt;h5 className=&quot;font-bold tracking-tight text-gray-900 row-span-3&quot;&gt;{productName}&lt;/h5&gt;
    &lt;p className=&quot;text-gray-900 text-sm row-span-4&quot;&gt;{shortDesc}&lt;/p&gt;
    &lt;div className=&quot;flex items-center justify-between mb-2 row-span-1&quot;&gt;
        &lt;span className=&quot;font-bold text-gray-900&quot;&gt;&lt;Price priceWithTax={priceWithTax} currencyCode={currencyCode} /&gt;&lt;/span&gt;
    &lt;/div&gt;
&lt;/Card&gt;

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-4div 标签封装起来,创建一个包含 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

&lt;div className=&quot;p-3 grid grid-cols-3 gap-3&quot;&gt;
  &lt;Card className=&quot;bg-slate-300&quot;&gt;
    &lt;h5 className=&quot;font-bold tracking-tight text-gray-900 row-span-3&quot;&gt;{productName}&lt;/h5&gt;
    &lt;p className=&quot;text-gray-900 text-sm row-span-4&quot;&gt;{shortDesc}&lt;/p&gt;
    &lt;div className=&quot;flex items-center justify-between mb-2 row-span-1&quot;&gt;
      &lt;span className=&quot;font-bold text-gray-900&quot;&gt;&lt;Price priceWithTax=&quot;{priceWithTax}&quot; currencyCode=&quot;{currencyCode}&quot; /&gt;&lt;/span&gt;
    &lt;/div&gt;
  &lt;/Card&gt;
  &lt;Card className=&quot;bg-slate-300&quot;&gt;
    &lt;h5 className=&quot;font-bold tracking-tight text-gray-900 row-span-3&quot;&gt;{productName}&lt;/h5&gt;
    &lt;p className=&quot;text-gray-900 text-sm row-span-4&quot;&gt;{shortDesc}&lt;/p&gt;
    &lt;div className=&quot;flex items-center justify-between mb-2 row-span-1&quot;&gt;
      &lt;span className=&quot;font-bold text-gray-900&quot;&gt;&lt;Price priceWithTax=&quot;{priceWithTax}&quot; currencyCode=&quot;{currencyCode}&quot; /&gt;&lt;/span&gt;
    &lt;/div&gt;
  &lt;/Card&gt;
  &lt;Card className=&quot;bg-slate-300&quot;&gt;
    &lt;h5 className=&quot;font-bold tracking-tight text-gray-900 row-span-3&quot;&gt;{productName}&lt;/h5&gt;
    &lt;p className=&quot;text-gray-900 text-sm row-span-4&quot;&gt;{shortDesc}&lt;/p&gt;
    &lt;div className=&quot;flex items-center justify-between mb-2 row-span-1&quot;&gt;
      &lt;span className=&quot;font-bold text-gray-900&quot;&gt;&lt;Price priceWithTax=&quot;{priceWithTax}&quot; currencyCode=&quot;{currencyCode}&quot; /&gt;&lt;/span&gt;
    &lt;/div&gt;
  &lt;/Card&gt;
&lt;/div&gt;

Some resources here

huangapple
  • 本文由 发表于 2023年2月16日 03:31:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/75464630.html
匿名

发表评论

匿名网友

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

确定