【发布时间】:2017-12-08 02:18:37
【问题描述】:
更新感谢 LGSon 在下面的评论 Updated codepen
我正在尝试设置类似于圣杯的布局。这里的不同之处在于我正在寻找一个动态大小的“内容”部分,使其垂直和水平居中。
我已经能够使用 flexbox 使这个工作(用于大型显示器):Codepen here
html, body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
text-align: center;
}
.header {
height: 60px;
line-height: 60px;
width: 100%;
background: rgba(255, 0, 0, 0.5);
}
.content {
height: calc(100% - 120px);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background: rgba(0, 255, 0, 0.5);
}
.content p {
width: 50%;
}
.footer {
height: 60px;
line-height: 60px;
width: 100%;
background: rgba(0, 0, 255, 0.5);
}
.header, .footer {
font-weight: bold;
}
<div class="header">
Header
</div>
<div class="content">
<h1>I am the content</h1>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>
<div class="footer">
Footer
</div>
问题是,如果“内容”部分太大,或者视图太小,溢出不会启动,直到 div 超过 100% 垂直而不是(100% 高度 - 页眉和页脚高度)
我正在努力做到这一点,当有重叠时,整个页面都会滚动,而不仅仅是“内容部分”中有一个滚动条。
【问题讨论】:
-
您知道页眉和页脚与页面的其余部分一起滚动吗?这肯定不是我们想要的结果……
-
这是预期的最终结果吗? codepen.io/anon/pen/gRKOoz?editors=1100
-
嗨@JamesDouglas,目前不寻找粘性页眉和页脚,除非内容太小而无法像上面链接的桌面屏幕截图中那样查看。我认为这方面的引导术语是 Fixed 我不是在寻找。
-
@LGSon 谢谢你的魔法,这正是我一直在寻找的!