【问题标题】:Flex with max height最大高度弯曲
【发布时间】:2020-01-18 16:49:32
【问题描述】:

如何使用 flex 将左列(块)的高度设置为 100%?我有这样的 dom:

<LeftPanel>
  <Logo />
  <Profile />
  <Chat />
  <SocialButtons />
</LeftPanel>

LeftPanel 高度为 100%。 Chat 应该按可用空间增长或缩小,但事实并非如此。我应该如何使用 css(scss) flex 呢?

【问题讨论】:

  • 到目前为止你用过什么css?

标签: html css sass flexbox


【解决方案1】:

我不知道我是否得到了你想要做的,但如果你想让&lt;LeftPanel&gt; 成为屏幕的 100% 并且&lt;Chat&gt; 是垂直扩展的,你应该使用以下属性设置它的 CSS:

.LeftPanel {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

&lt;Logo&gt;,&lt;Profile&gt;&lt;SocialButtons&gt; 应该有一个定义的 height。比如下面的例子:

.Logo {
    height: 60px;
    width: 100%;
}

.Profile {
    height: 160px;
    width: 100%;
}

.SocialButtons {
    height: 50px;
    width: 100%;
}`

那么,这里有两个可能的技巧:

.Chat {
    flex-grow: 1;
}`

使用flex-grow,您可以将弹性项目的扩展系数设置为高于其他项目,请阅读文档here

.Chat {
    height: 100vh;
}`

如果.Chat 的父级不使用flex-wrap 包装其内容,则.Chat 将占用父级空间的剩余空间。

【讨论】:

  • 它是如何工作的? .Chat with height: 100vh 它是视口高度的 100%,但在我的情况下,它只是所有可用空间。解决了,但是看不懂
  • 当你用 flex 元素包裹子元素时,它会自动使子元素成为“灵活元素”,因此它会从 flexbox 行为中获取一些默认属性。如果您想了解更多信息,我建议您阅读以下文档:developer.mozilla.org/en-US/docs/Web/CSS/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-05
  • 2016-04-09
  • 2019-11-26
  • 2011-01-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多