gpt4 book ai didi

html - 为 flex 元素设置特定高度

转载 作者:太空宇宙 更新时间:2023-11-04 02:03:07 25 4
gpt4 key购买 nike

我有 3 个 flex 元素:页眉、内容和页脚。我希望一切都可以 flex ,但标题正好是 250px ...我添加了一个样式 .height-250 {max-height: 250px;} 但它不起作用。

/* GRID */
.grid {
display: flex;
}
.col {
background-color: rgba(100, 255, 255, 0.1);
border: 1px solid rgb(100, 255, 225);
padding: 5px;
}
.col-1-12 {
flex-basis: 8.3333%;
}
.col-2-12 {
flex-basis: 16.6666%;
}
.flex-column {
flex-direction: column;
}
.full-width {
flex-grow: 100;
}
.wrapper,
html,
body {
height: 100%;
margin: 0;
}
.wrapper {
display: flex;
flex-direction: column;
}
.height-250 {
max-height: 250px;
}
<div class="wrapper grid flex-column">
<div class="col col-1-12 height-250">Header</div>
<div class="grid col full-width col-2-12">Content</div>
<div class="col col-1-12">Footer</div>
</div>

最佳答案

你应该使用 flex: 0 0 250px 而不是 max-height: 250pxflex-direction: column 它将设置高度元素到 250px。

.grid {
display: flex;
}
.col {
background-color: rgba(100, 255, 255, 0.1);
border: 1px solid rgb(100, 255, 225);
padding: 5px;
}
.col-1-12 {
flex-basis: 8.3333%;
}
.col-2-12 {
flex-basis: 16.6666%;
}
.flex-column {
flex-direction: column;
}
.full-width {
flex-grow: 100;
}
.wrapper,
html,
body {
height: 100%;
margin: 0;
}
.wrapper {
display: flex;
flex-direction: column;
}
.height-250 {
flex: 0 0 250px;
}
<div class="wrapper grid flex-column">
<div class="col col-1-12 height-250">Header</div>
<div class="grid col full-width col-2-12">Content</div>
<div class="col col-1-12">Footer</div>
</div

关于html - 为 flex 元素设置特定高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41381222/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com