设计带有固定标头,页脚和可滚动主内容的100VH布局
我正在尝试创建下图所示的布局。我不做的是限制< main>
标签的增长(以黄色为颜色)并添加垂直滚动。我还创建了一个交互式示例在这里我试图完成的工作并在下面看到我的代码。
.flex {
display: flex;
}
.h-screen {
height: 100vh;
}
.w-96 {
width: 24rem;
}
.flex-shrink-0 {
flex-shrink: 0;
}
.flex-grow {
flex-grow: 1;
}
.flex-col {
flex-direction: column;
}
.overflow-y-auto {
overflow-y: auto;
}
.bg-gray-300 {
background-color: rgb(209 213 219);
}
.bg-red-400 {
background-color: rgb(248 113 113);
}
.bg-blue-300 {
background-color: rgb(147 197 253);
}
.bg-red-100 {
background-color: rgb(254 226 226);
}
<div class="bg-gray-300">
<div class="flex h-screen w-96 flex-col">
<div class="flex flex-grow flex-col">
<header>Header</header>
<main class="flex-grow overflow-y-auto">
<div class="h-screen bg-red-400"></div>
<div class="h-screen bg-blue-300"></div>
</main>
<footer>Footer 2</footer>
</div>
<footer class="flex-shrink-0 bg-red-100">Footer 1</footer>
</div>
</div>
I am trying to create the layout pictured below. What I fail to do is to limit the growth of the <main>
tag (coloured in yellow) and add vertical scroll. I have created also an interactive example here of what I am trying to accomplish and see my code below.
.flex {
display: flex;
}
.h-screen {
height: 100vh;
}
.w-96 {
width: 24rem;
}
.flex-shrink-0 {
flex-shrink: 0;
}
.flex-grow {
flex-grow: 1;
}
.flex-col {
flex-direction: column;
}
.overflow-y-auto {
overflow-y: auto;
}
.bg-gray-300 {
background-color: rgb(209 213 219);
}
.bg-red-400 {
background-color: rgb(248 113 113);
}
.bg-blue-300 {
background-color: rgb(147 197 253);
}
.bg-red-100 {
background-color: rgb(254 226 226);
}
<div class="bg-gray-300">
<div class="flex h-screen w-96 flex-col">
<div class="flex flex-grow flex-col">
<header>Header</header>
<main class="flex-grow overflow-y-auto">
<div class="h-screen bg-red-400"></div>
<div class="h-screen bg-blue-300"></div>
</main>
<footer>Footer 2</footer>
</div>
<footer class="flex-shrink-0 bg-red-100">Footer 1</footer>
</div>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)