gpt4 book ai didi

html - 当所有 child 都有 flex 属性时, parent 的 justify-content 重要吗?

转载 作者:行者123 更新时间:2023-12-04 08:35:25 29 4
gpt4 key购买 nike

.parent {
background-color: yellow;
display: flex;
justify-content: space-evenly;
}
.parent > div {
background-color: lightblue;
flex: 1;
margin: 5px;
}
<div class="parent">
<div>Child #1</div>
<div>Child #2</div>
<div>Child #3</div>
</div>

在上面的简单例子中,有一个父级 div有3个 child div s。所有的 child 都有一个 flex: 1属性(property),因此它们都在其父级内部平均分配。此时,是否属性 justify-content: space-evenly parent 实际上算吗?无论我插入什么值,结果总是相同的。完全可以删除吗?

最佳答案

The justify-content property aligns flex items along the main axis of the current line of the flex container. This is done after any flexible lengths and any auto margins have been resolved. Typically it helps distribute extra free space leftover when either all the flex items on a line are inflexible, or are flexible but have reached their maximum size. It also exerts some control over the alignment of items when they overflow the line.ref


如果您没有多余的空间,那么您可以放心地省略该属性,并且不会有任何变化。
它可以在两种情况下产生影响:
  • 您的布局是动态的,您的元素可能会缩小尺寸并创建一个可用空间
  • 您正在使用 justify-content:inherit在 flex 元素中获取父值(顺便说一下,这不是很常见的情况)
  • 关于html - 当所有 child 都有 flex 属性时, parent 的 justify-content 重要吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64822165/

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