gpt4 book ai didi

Setting a width to an item in a row prevents justifying the second item in the same row using TailwindCSS(设置行中某项的宽度可防止使用TailwinCSS对齐同一行中的第二项)

转载 作者:bug小助手 更新时间:2023-10-28 10:22:39 25 4
gpt4 key购买 nike



I have three items in two rows like:

我有两行的三个项目,例如:


<div class="grid grid-cols-12">
<div class="col-span-12 border-b-4 border-black">Item1</div>
<div class="col-span-2 border-r-4 border-black">Item2</div>
<div class="col-span-10">Item3</div>
</div>

I need to reduce the default width of Item2 using w-14 and I need to justify Item3 to the left. I am using tailwind CSS v3.3.3.

我需要使用w-14减小Item2的默认宽度,并且需要将Item3向左对齐。我使用的是顺风CSS3.3.3版。


After adding w-14 to Item2 I tried various justifying options like justify-stretch, justify-items-stretch, justify-items-start, justify-self-auto, etc. to Item3, but none of those options helped justifying Item3 to the left (immediately adjacent to Item2). Item3 seem to stay put in its position.

在将w-14添加到Item2后,我尝试了各种对齐选项,如对齐-拉伸、对齐-项目-拉伸、对齐-项目-开始、对齐-自动等,但这些选项都不能帮助对齐Item3向左(紧挨着Item2)。项目3似乎保持在自己的位置上。


Here is what I tried:

以下是我尝试的:


<div class="grid grid-cols-12 justify-items-stretch">
<div class="col-span-12 border-b-4 border-black">Item1</div>
<div class="col-span-2 border-r-4 border-black w-14 justify-self-start">Item2</div>
<div class="col-span-10">Item3</div>
</div>

which reduces the width of Item2 but does not left justify Item3.

这会减小Item2的宽度,但不会使Item3对齐。


Any hints on this would be much appreciated.

任何关于这方面的提示将不胜感激。


更多回答
优秀答案推荐

w-6/12 applies width: 50% and this 50% would be 50% of its column span, 2. The element would still occupy two columns but would only take up the width of one, hence it this one-column gap makes it look like the third item is not up against the second item.

W-6/12适用宽度:50%,这50%将是其列跨度的50%,2。元素仍将占据两列,但仅占据一列的宽度,因此,这种一列间隙使其看起来像是第三项与第二项不在一起。


To work around this, consider changing the second item to only occupy one grid column instead without the width and justify-self property values, thus giving the same visual effect. However, the second item will only occupy one grid column track, thus allowing the third item to be visually closer.

要解决此问题,请考虑将第二项更改为只占用一个网格列,而不使用宽度和自对齐属性值,从而获得相同的视觉效果。但是,第二个项目将仅占用一个轴网柱轨道,从而使第三个项目在视觉上更接近。




<script src="https://cdn.tailwindcss.com/3.3.3"></script>

<div class="grid grid-cols-12 justify-items-stretch">
<div class="col-span-12 border-b-4 border-black">Item1</div>
<div class="col-span-1 border-r-4 border-black">Item2</div>
<div class="col-span-10">Item3</div>
</div>






Question edit additional solution


Consider adjusting the column widths of the grid layout so that the second item's column size is what you'd want. This will mean that the third grid track where the third element starts from, will be at the end of the second item. This will mean the third element starts after the second item:

考虑调整网格布局的列宽,以便第二个项目的列大小符合您的要求。这意味着第三个元素开始的第三个栅格轨迹将位于第二个项目的末尾。这将意味着第三个元素在第二个项目之后开始:




<script src="https://cdn.tailwindcss.com/3.3.3"></script>

<div class="grid grid-cols-[repeat(2,calc(theme(spacing.14)/2))_repeat(10,1fr)] justify-items-stretch">
<div class="col-span-12 border-b-4 border-black">Item1</div>
<div class="col-span-2 border-r-4 border-black">Item2</div>
<div class="col-span-10">Item3</div>
</div>




更多回答

Thanks @Wongjn, I have edited my post to update w-6/12 to w-14. Your code does not reduce the width of Item2. After applying w-14 to Item2 to reduce the width, I need to left justify Item3.

谢谢@Wongjn,我已经编辑了我的帖子,将w-6/12更新为w-14。您的代码不会减小Item 2的宽度。在将w-14应用于Item 2以减小宽度之后,我需要左对齐Item 3。

I have added a solution to your changed question.

我已经为您更改的问题添加了解决方案。

Thanks @Wongjn, that is exactly what I am looking for! I have marked this as the accepted answer.

谢谢@Wongjn,这正是我正在寻找的!我已将此标记为可接受的答案。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com