为什么flex-shrink在inline-flex中不起作用
为什么项目不缩小内联用品。但是它在正常的弹性中正常工作。也许应该这样起作用,我不知道。也许它是规格中的某个地方,但我找不到任何相关的东西。如果有人能解释这一点,我会很感激。
.container {
width: 100px;
margin 0 auto;
margin-top: 100px;
background-color: green;
}
.inline-flex {
display: inline-flex;
margin-bottom: 10px;
}
.flex {
display: flex;
}
.item {
width: 50px;
height: 50px;
margin-right: 5px;
background-color: blue;
}
<div class="container">
<div class="inline-flex">
<div class="item">no-shrink</div>
<div class="item">no-shrink</div>
<div class="item">no-shrink</div>
</div>
<div class="flex">
<div class="item">shrink</div>
<div class="item">shrink</div>
<div class="item">shrink</div>
</div>
</div>
Why items dont shrink in inline-flex. But it works fine in normal flex. Maybe it is supposed to work that way, I dont know. Maybe it is somewhere in the spec but I coudn't find anything related. I would be grateful if someone could explain this.
.container {
width: 100px;
margin 0 auto;
margin-top: 100px;
background-color: green;
}
.inline-flex {
display: inline-flex;
margin-bottom: 10px;
}
.flex {
display: flex;
}
.item {
width: 50px;
height: 50px;
margin-right: 5px;
background-color: blue;
}
<div class="container">
<div class="inline-flex">
<div class="item">no-shrink</div>
<div class="item">no-shrink</div>
<div class="item">no-shrink</div>
</div>
<div class="flex">
<div class="item">shrink</div>
<div class="item">shrink</div>
<div class="item">shrink</div>
</div>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如前所述,
flex
的作用像block
和inline-flex-flex
喜欢inline-block
孩子的行为相同。 flex-items.Item
在外观相同时的行为完全不同,因为它们的行为受Flex-Container的影响(.flex
和.inline- flex
)。除了具有不同的显示
值的弹性容器外,没有其他差异。.Item
的.inline-flex
保留了50px的宽度.Item
的
.flex 具有宽度为34.6687px,我仍然没有弄清楚为什么这是为什么,但是我有3种不同的解决方案:
.container
太小,增加宽度。参见示例a
图i
更改
flex> flex
.Item
s的属性或分配最小宽度
参见示例B
图II
As stated before,
flex
acts like ablock
andinline-flex
likeinline-block
on the outside and their children behave identically. The flex-items.item
are acting totally different when they should appear the same because their behavior is influenced by the flex-container (.flex
and.inline-flex
). Aside from the flex-containers having differentdisplay
values, there are no other differences..item
of.inline-flex
has retained it's width of 50px.item
of.flex
has a width of 34.6687pxI still haven't figured out why this is but I have 3 different solutions:
.container
is too small, increase it's width.See Example A
Figure I
Change the
flex
properties of.item
s or assignmin-width
See Example B
Figure II