Material UI Stack弹性盒子全宽度

huangapple go评论128阅读模式
英文:

Material UI Stack flexbox full width

问题

如何在不使用 width:100% 的情况下使用 flexbox 使 Item 2 充满整个宽度?

<Box sx={{ width: '100%' }}>
  <Stack spacing={2} alignItems="flex-start">
    <Item>Item 1</Item>
    <Item>Item 2</Item>
    <Item>Item 3</Item>
  </Stack>
</Box>
英文:

How can I make Item 2 full width without width:100% using flexbox?

&lt;Box sx={{ width: &#39;100%&#39; }}&gt;
  &lt;Stack spacing={2} alignItems=&quot;flex-start&quot;&gt;
    &lt;Item&gt;Item 1&lt;/Item&gt;
    &lt;Item&gt;Item 2&lt;/Item&gt;
    &lt;Item&gt;Item 3&lt;/Item&gt;
  &lt;/Stack&gt;
&lt;/Box&gt;

答案1

得分: 1

如果您希望项目2尽可能多地增长,可以执行以下操作:

flex: 1;

但您必须确保父Stack组件是

display: flex;

但请详细说明您希望项目2如何显示。如果您希望它独占一行,或与其他两个项目共享同一行,请明确指定。

英文:

If you want Item 2 to grow as much as it can you can do:

flex: 1;

But you have to make sure that the parent Stack component is

display: flex;

But specify more in detail how exactly you want Item 2 to be displayed. If you want it to be alone in a single row, or share the same row as the other two items.

huangapple
  • 本文由 发表于 2023年7月5日 01:25:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/76614773.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定