我需要控制接近桌面行为的高度布局:
对于一个层次结构,可以很容易地使用flex来实现。但是我需要这样的布局:
<top height="...rem">
<header height="...rem"/>
<main> // stretched height
<main2> // stretched height
<content>
limited height by main2 and add scroll if necessary
</content>
</main2>
<footer height="...rem"/>
</main>
</top>
我做了概念验证,可以解决内容弯曲和绝对位置问题。
https://jsfiddle.net/2Lfgq93h/6/
那么问题:
答案 0 :(得分:1)
所以一个问题是,似乎没有必要像您在小提琴中所称的那样<main2>
元素或.submain
类。
主要要注意的是,您希望一些flex元素(我专门讲的是display: flex
的父级的子级)具有固定的大小(例如,页眉和页脚),以及一些大小可变。为此,您可以结合使用flex: none
和flex: 1 1
* {
box-sizing: border-box;
}
.height-limit {
height: 10rem;
display: flex;
flex-direction: column;
}
header {
flex: none;
padding: 1rem;
background: #bdc3c7;
}
.main {
flex: 1 1;
padding: 1rem;
display: flex;
flex-direction: column;
background: #e74c3c;
}
.content {
flex: 1 1;
overflow: auto;
background: #3498db;
}
footer {
flex: none;
padding: 1rem;
background: #2ecc71;
}
<div class="height-limit">
<header>header</header>
<div class="main">
<div class="content">
some body some body some body some body some body some body some body some body some body some body some body some body some body some body some body some body some body some body some body some body some body some body some body some body some body some body some body some body some body some body some body some body some body some body some body some body some body some body some body some body some body some body some body some body some body some body some body some body some body some body some body some body some body some body some body some body some body
</div>
<footer>footer</footer>
</div>
</div>