为弹性项目设置特定高度

Ale*_*lin 0 html css flexbox

我有 3 个弹性项目:页眉、内容和页脚。我希望一切都可以弯曲,但标题正好是 250 像素...我添加了一个样式,.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;
}
Run Code Online (Sandbox Code Playgroud)
<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>
Run Code Online (Sandbox Code Playgroud)

Nen*_*car 5

相反的max-height: 250px,你应该使用flex: 0 0 250px,并flex-direction: column会设置元素的高度250像素。

.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;
}
Run Code Online (Sandbox Code Playgroud)
<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
Run Code Online (Sandbox Code Playgroud)