1
在下面SSCCE,如何在表单中粘贴页眉和页脚STICKY(即分别固定在表单的顶部和底部)?
我想使
.header
和.footer
坚持自己的父容器的顶部和底部(分别)。所以我申请了top:0px
和bottom:0px
位置偏移量给他们。但这似乎并不奏效。问题是为什么以及如何实现我想要的?我想使
.header
和.footer
固定,这样,当滚动内容时,该.header
和.footer
没有;他们应该保持固定。我怎么做?应用position:fixed
正在使他们坚持整个页面(而不是他们的父母)的顶部和底部(分别)。
body {
background-color: rgba(0, 0, 0, 0.5);
}
.container {
width: 40%;
height: 70vh;
background-color: white;
margin: 5% auto;
position: relative;
}
.header {
border-bottom: 1px solid grey;
top: 0px;
position:absolute;
}
.footer {
border-top: 1px solid grey;
bottom: 0px;
position:absolute;
}
.content {
padding:20px;
overflow:auto;
}
<form class="container">
<div class="header">I am the header</div>
<div class="content">I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content. I am the content</div>
<div class="footer">I am the footer</div>
</form>
非常感谢你 – Solace
嘿如果我想将'overflow'属性应用于'.content'而不是整个'.container'?为什么它不工作(请参阅有问题的编辑代码)? – Solace
哦,是的,非常感谢。 – Solace