【发布时间】:2020-07-31 03:37:43
【问题描述】:
对于一个 wrap flex 盒子,是否可以在盒子堆叠后修改盒子的行为? (在纯 CSS 中)。
以这个玩具为例,
p {
border: dashed 1px;
}
#container {
display: flex;
flex-wrap: wrap;
}
#item1 {
flex: 1 1 auto;
display: flex;
flex-wrap: wrap;
flex-direction: column;
align-items: end;
align-content: end;
background: blue;
}
#item2 {
flex: 3 1 auto;
display: flex;
flex-wrap: wrap;
flex-direction: column;
align-items: start;
align-content: start;
background: red;
}
<div id="container">
<div id="item1">
<p>This is the item 1.</p>
<p>item 1.</p>
</div>
<div id="item2">
<p>This is the item 2.</p>
<p>item 2.</p>
</div>
</div>
一旦蓝色框被堆叠(通过调整窗口大小),是否可以将 p 项目居中。我期待的是这样的:
#item2: wrap {
align-items: center;
align-content: center;
}
在纯 CSS 中真的可以吗?
【问题讨论】:
-
没有。您无法检测到弹性项目何时换行。
-
@Turnip 我们可以在 flex-items 上使用任何 CSS 属性,唯一的情况是使用 flex-basis 和 width,在这种情况下会应用 flex-basis。
-
@ImranRafiqRather 你完全误解了这个问题。
-
@萝卜:我的坏兄弟,我现在明白了。让我试着看看如何处理这个问题。我接受我的错误并感谢您纠正我:)
-
@Turnip 刚刚更新了答案,谢谢你阻止我分享错误的信息。上帝保佑:)