简体   繁体   English

不同高度的tailwindcss flexcols

[英]tailwindcss flexcols with different height

I want to split the div into two parts with individuals heights.我想将 div 分成具有个人高度的两部分。 But the flex and grid classes from tailwind will stretch the height of the smaller child to the height of the other child.但是 tailwind 的 flex 和 grid 类会将较小的孩子的高度拉伸到另一个孩子的高度。

At the moment it looks like this目前它看起来像这样

 <link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet"/> <div class="flex flex-row"> <div class="bg-green-500 w-1/2"> <div class="h-4"></div> </div> <div class="bg-red-500 w-1/2"> <div class="h-12"></div> </div> </div>

How do I achieve individual height?如何达到个人身高? (the content of the Childs is programmatically set and does not always have the same height) (Childs 的内容以编程方式设置,并不总是具有相同的高度)

Just move the h- class on the parent div只需在父 div 上移动 h- class

 <link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet"/> <div class="flex flex-row h-min"> <div class="h-4 bg-green-500 w-1/2"> <div class=""></div> </div> <div class="h-12 bg-red-500 w-1/2"> <div class=""></div> </div> </div>

In flexbox, the default behaviour for align-items is stretch .在 flexbox 中, align-items的默认行为是stretch That will in effect match the heights of all your elements that are in a line.这实际上将匹配一行中所有元素的高度。 You need to change that to flex-start instead.您需要将其更改为flex-start

Add the .items-start class.添加.items-start class。

 <link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet"/> <div class="flex flex-row items-start"> <div class="bg-green-500 w-1/2"> <div class="h-4"></div> </div> <div class="bg-red-500 w-1/2"> <div class="h-12"></div> </div> </div>

https://developer.mozilla.org/en-US/docs/Web/CSS/align-itemshttps://developer.mozilla.org/en-US/docs/Web/CSS/align-items

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM