首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >为什么柔韧的东西在没有弯曲生长的情况下扩展全高度?

为什么柔韧的东西在没有弯曲生长的情况下扩展全高度?
EN

Stack Overflow用户
提问于 2016-12-28 19:50:34
回答 1查看 249关注 0票数 1

我有以下代码:

代码语言:javascript
运行
复制
.ai-container,
.ai-overlay {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  justify-content: center;
}
.ai-overlay {
  background-color: black;
  opacity: .2;
  z-index: 1000;
}
.ai-dialog {
  z-index: 1001;
  display: flex;
  flex-direction: column;
  border: 1px solid darkgray;
  border-radius: 5px;
  background-color: white;
  min-width: 300px;
  box-shadow: 0px 0px 15px #444;
  overflow: hidden;
}
.ai-header,
.ai-footer,
.ai-body {
  padding: 10px;
}
.ai-header {
  background-color: hsl(0, 0%, 20%);
  color: white;
  display: flex;
  font-size: 1.1em;
  justify-content: space-between;
}
.ai-footer {
  display: flex;
  background-color: lightgray;
  justify-content: space-between;
}
代码语言:javascript
运行
复制
<div class="ai-container">
  <div class="ai-overlay"></div>
  <div class="ai-dialog">
    <div class="ai-header">
      <span>This is the header</span>
      <span>X</span>
    </div>
    <div class="ai-body">This is the body</div>
    <div class="ai-footer">
      <span>
          <button>Submit</button>
          <button>Lookup</button>
      </span>
      <button>Cancel</button>
    </div>
  </div>
</div>

您可以在这里看到结果:http://plnkr.co/edit/5SOxkMV9qQ86m6d2jyT0?p=preview

然而,由此产生的“对话框”被拉伸以填充整个垂直空间。

如果我有flex-grow: 1的话,我会料到这一点,但我没有。

如果将以下内容添加到css中:

代码语言:javascript
运行
复制
.ai-container, .ai-overlay {
    ... /*all the previous settings */
    align-items: center;
}

对话看起来就像是我所期待的..。只要足够高就能符合内容。我假设删除align-items只会将对话框移动到浏览器窗口的顶部,而不会影响高度。

我在这里错过了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-12-28 20:00:38

我假设删除align-items只会将对话框移动到浏览器窗口的顶部,而不会影响高度。

你们关系很好。假设align-items的默认值是flex-start。实际上,默认值是stretch

这意味着,除非初始设置被覆盖,否则flex项将始终展开以覆盖容器的交叉轴的完整长度。

您可以使用align-items: flex-startcenter等重写默认值。

下面是一些更详细的信息:How to disable equal height columns in Flexbox?

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41368783

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档