css - Flexbox 主体和主最小高度

标签 css height flexbox

https://jsfiddle.net/vz7cLmxy/

我试图让 body 拉伸(stretch),但最小高度不起作用。我已经阅读了其他相关主题,但无法理解它。

CSS 和 html

body,
html {
  padding: 0;
  margin: 0;
  min-height: 100%;
}

body {
  display: flex;
  background: #eee;
  flex-direction: column;
}

.menu {
  background: red;
  color: #fff;
  padding: 10px;
}

.wrap {
  display: flex;
}

.sidebar {
  background: #ddd;
  width: 300px;
}

.main {
  background: #ccc;
  flex: 1;
}

.footer {
  background: #000;
  color: #fff;
  padding: 10px;
}
<div class="menu">Menu</div>

<div class="wrap">
  <div class="sidebar">Sidebar</div>
  <div class="main">Main</div>
</div>

<div class="footer">Footer</div>

预期的结果是,如果 main 小于 100%,则它会被拉伸(stretch)以填充高度。

最佳答案

在居中元素上使用 flex: 1:

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

.Site-content {
  flex: 1;
  background-color:#bbb;
}
<body class="Site">
  <header>This is the header text ☺</header>
  <main class="Site-content">…</main>
  <footer>This is the footer text ☻</footer>
</body>

关于css - Flexbox 主体和主最小高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37431563/

相关文章:

html - 内容 DIV 最小高度在 IE 11 中不起作用且页脚太低

css - 如何在移动横向 View 中定位图像

jQuery - 动态 div 高度等于整个窗口的高度

css - 柔性 : wrapped items with same width as the rest

html - 无法滚动到容器溢出的 flex 元素顶部

html - Bootstrap 模态全屏问题

css - 在 Jade 中加载谷歌图表

javascript - jQuery 从顶部获取高度

html - 图层不会拉伸(stretch)到包含图像的高度

HTML Flexbox 画廊