我有以下代码:
.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;
}
<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中:
.ai-container, .ai-overlay {
... /*all the previous settings */
align-items: center;
}
对话看起来就像是我所期待的..。只要足够高就能符合内容。我假设删除align-items
只会将对话框移动到浏览器窗口的顶部,而不会影响高度。
我在这里错过了什么?
发布于 2016-12-28 20:00:38
我假设删除
align-items
只会将对话框移动到浏览器窗口的顶部,而不会影响高度。
你们关系很好。假设align-items
的默认值是flex-start
。实际上,默认值是stretch
。
这意味着,除非初始设置被覆盖,否则flex项将始终展开以覆盖容器的交叉轴的完整长度。
您可以使用align-items: flex-start
、center
等重写默认值。
下面是一些更详细的信息:How to disable equal height columns in Flexbox?
https://stackoverflow.com/questions/41368783
复制相似问题