gpt4 book ai didi

html - 如何开始一个新行并将换行符与 flexbox 中的另一个元素对齐?

转载 作者:行者123 更新时间:2023-12-05 01:53:06 26 4
gpt4 key购买 nike

我有一个 flexbox,里面有不同的元素。

enter image description here

当它换行时,我想将这条新行与 flexbox 第一行的第二个元素对齐,但我不知道该怎么做。元素的宽度将根据内部文本动态变化。

enter image description here

div {
font-family: arial, sans-serif;
margin: 5px;
color: white;
border: 1px dotted black;
}

.parent {
display: flex;
flex-wrap: wrap;
width: 300px;
}

.unique_element {
background-color: Crimson;
width: 30%;
padding: 10px 10px 10px 10px;
}

.child {
background-color: CornflowerBlue;
padding: 10px 10px 10px 10px;
}
<div class="parent">
<div class="unique_element">First</div>
<div class="child">Second</div>
<div class="child">Third</div>
<div class="child">Fourth</div>
<div class="child">Fifth</div>
</div>

最佳答案

When it wraps onto a new line I want to align this new line with the 2nd item on the first row of the flexbox.

因此,真正的问题是:发生换行时如何重新排列 flex 元素?

因为 HTML 和 CSS 本身有 no concept of when elements wrap ,他们无法控制这种情况。您必须使用媒体查询或 JavaScript 来处理它。

一旦选择了检测换行的方法,就可以使用 order 属性重新排列元素。

关于html - 如何开始一个新行并将换行符与 flexbox 中的另一个元素对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71244070/

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