header,
nav,
main {
border: 1px solid red;
}
.row {
display: flex;
flex: 0 0 100%;
}
.col {
flex-grow: 1;
flex-shrink: 1;
flex-basis: 0;
}
.col_3 {
flex: 0 0 25%;
}
<html>
<hedad></hedad>
<body>
<div>
<header>Header</header>
<div class="row">
<div class="col col_3">
<nav>
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
</nav>
</div>
<div class="col">
<main>main</main>
</div>
</div>
</div>
</body>
</html>
鉴于附加了标记,无论如何我只能使用css并且不使用固定高度来使用侧边栏<nav>
元素和main
元素来填充视口底部的可用高度?
答案 0 :(得分:0)
您需要定义至少一些height:100%
或使用vh
单位。这是一个例子:
body,
html,
nav,
main {
height: 100%;
}
* {
box-sizing:border-box;
}
body {
display: flex;
flex-direction: column;
margin: 0;
}
header,
nav,
main {
border: 1px solid red;
}
.row {
display: flex;
flex: 1;
}
.col {
flex-grow: 1;
flex-shrink: 1;
flex-basis: 0;
}
.col_3 {
flex: 0 0 25%;
}
&#13;
<header>Header</header>
<div class="row">
<div class="col col_3">
<nav>
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
</nav>
</div>
<div class="col">
<main>main</main>
</div>
</div>
&#13;
以下是使用vh
单位的另一个想法:
nav,
main {
height: 100%;
}
* {
box-sizing:border-box;
}
body {
display: flex;
flex-direction: column;
margin: 0;
height:100vh;
}
header,
nav,
main {
border: 1px solid red;
}
.row {
display: flex;
flex: 1;
}
.col {
flex-grow: 1;
flex-shrink: 1;
flex-basis: 0;
}
.col_3 {
flex: 0 0 25%;
}
&#13;
<header>Header</header>
<div class="row">
<div class="col col_3">
<nav>
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
</nav>
</div>
<div class="col">
<main>main</main>
</div>
</div>
&#13;