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/