我使用css和Flexbox创建了一个布局,问题是页脚div在加载时显示在页面的底部,但是内容超出了它,因此,当您滚动页脚时,该页脚正浮在页面中间。我不确定要更改什么。
我将页脚更改为粘性,将底部更改为0px。它有点可以调整其他div的边距,但是它不是很干净。我希望继续使用flexbox属性,而只是将它们堆叠,但这似乎不起作用?我还调整了其他div的min-max高度,但是一旦窗口缩小到最小高度以上,页脚就会浮在其余内容上。
链接到代码JSFiddle
.footer{
height:40px;
display:flex;
align-items:center;
justify-content:center;
width:100%;
background-color:purple;
}
我怀疑页脚会遵守堆叠顺序,只是在其余内容下显示,就像主体在页眉下一样。
答案 0 :(得分:1)
这是您在'.content'类上设置的高度。将height: calc(100vh - 100px)
更改为min-height: calc(100vh - 100px)
除非您希望页脚和页眉始终可见,否则只需添加overflow: auto
即可使内容滚动
答案 1 :(得分:0)
从height: calc(100vh - 100px);
类中删除.content
body,
html {
height: 100%;
width: 100%;
padding: 0;
margin: 0;
}
.bodywrap {
display: flex;
flex-wrap: wrap;
align-content: space-between;
background-color: black;
}
.header {
display: flex;
justify-content: space-between;
width: 100%;
height: 60px;
background-color: brown;
}
.hleft {
display: flex;
align-items: center;
justify-content: center;
width: 250px;
background-color: lightgreen;
}
.hmid {
display: flex;
align-items: center;
justify-content: center;
flex-grow:1;
font-size: calc(1.5vw);
background-color: orange;
}
.hright {
display: flex;
align-items: center;
justify-content: center;
width: 400px;
background-color: pink;
}
.content {
display: flex;
justify-content: space-between;
background-color: darkblue;
}
.lmenu {
display: flex;
width: 250px;
flex-wrap: wrap;
align-content: space-between;
height: 100%;
min-height: 600px;
background-color: lightgrey;
overflow: hidden;
}
.ltop {
display: flex;
align-items: center;
justify-content: center;
height: 150px;
width: 100%;
background-color: blue;
}
.lmid {
height: 50px;
width: 100%;
background-color: green;
}
.lbot {
display: flex;
align-items: center;
justify-content: center;
height: 50px;
width: 100%;
background-color: yellow;
}
.rmaincont {
display: flex;
flex-wrap: wrap;
align-content: flex-start;
width: calc(100vw - 250px);
background-color: grey;
}
.note {
width: 100%;
display: flex;
align-items: center;
justify-content: center;
background-color: lightblue;
height: 50px;
}
.main {
display: flex;
flex-wrap: wrap;
align-items: flex-start;
height: calc(100vh - 50px);
min-height: 550px;
width: 100%;
padding-left: 20px;
background-color: red;
}
.footer {
height: 40px;
display: flex;
align-items: center;
justify-content: center;
width: 100%;
background-color: purple;
}
<!DOCTYPE html>
<html>
<head>
<title>Mid-Valley Intranet</title>
<link rel="stylesheet" type="text/css" href="css/cstyle.css">
</head>
<body>
<div class="bodywrap">
<header class="header">
<div class="hleft">Left</div>
<div class="hmid">Mid</div>
<div class="hright">Right</div>
</header>
<div class="content">
<div class="lmenu">
<div class="ltop">
Top
</div>
<div class="lmid">
Mid
</div>
<div class="lbot">
Bot
</div>
</div>
<div class="rmaincont">
<div class="note">
Notice
</div>
<div class="main">
Main Content
</div>
</div>
</div>
<footer class="footer">
Footer Text
</footer>
</div>
</body>
</html>
答案 2 :(得分:0)
要完成这项工作,需要做一些事情:
最初,滚动发生在身体上。我在主体上添加了"batchSize"
,并通过“ bodywrap”类将overflow: hidden
添加到了div。
我添加了位置粘滞和底部0,但带有供应商前缀:
overflow-y: auto
bottom: 0;
position: -webkit-sticky;
position: -moz-sticky;
position: -ms-sticky;
position: -o-sticky;
这是新版本的演示: