【发布时间】:2022-05-02 16:00:26
【问题描述】:
正如标题所述,我正在尝试使用 Tailwind CSS 让父 div 中的 div 跨列对齐。但是,由于上传到每列的图像大小不同,它们没有对齐。我不想调整图像大小。我用红色圈出了我想要在底部对齐的 div。 Github Repo
我已经尝试过引用here的不同设置
我想要对齐的特定子 div 来自 <div className="p-4 bg-black">
我想知道是否有人可以提供帮助?
return (
<div className="flex justify-end">
<div className="px-4" style={{ maxWidth: '1600px' }}>
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4 pt-4">
{
nfts.map((nft, i) => (
<div key={i} className="border shadow rounded-xl overflow-hidden">
<img src={nft.image} />
<div className="p-4">
<p style={{ height: '64px' }} className="text-2xl font-semibold">{nft.name}</p>
<div style={{ height: '70px', overflow: 'hidden' }}>
<p className="text-gray-400">{nft.description}</p>
</div>
</div>
<div className="p-4 bg-black">
<p className="text-2xl mb-4 font-bold text-white">{nft.price} Matic</p>
<button className="w-full bg-pink-500 text-white font-bold py-2 px-12 rounded"
onClick={() => buyNft(nft)}>Buy</button>
</div>
</div>
))
}
</div>
</div>
</div>
) }
【问题讨论】:
-
尝试将固定
min-height设置为每张卡的根div并使用content-between -
由于高度固定,所有卡片的垂直填充都相同。
content-between会将每张卡片内的元素定位在垂直边缘
标签: javascript css next.js multiple-columns tailwind-css