html file
* {
margin: 0px;
}
.header {
background-color: tomato;
height: 60px;
position: sticky;
top: 0;
}
.contents {
height: 2500px;
}
.footer {
position: sticky;
bottom: 0;
height: 65px;
background-color: green;
}
<body>
<div>
<div class="contents">
<div class="header">
</div>
1234<br/>1234<br/>1234<br/>1234<br/>1234<br/>1234<br/>1234<br/>1234<br/>1234<br/>1234<br/>1234<br/>1234<br/>1234<br/>1234<br/>1234<br/>1234<br/>1234<br/>1234<br/>1234<br/>1234<br/>1234<br/>1234<br/>
<div class="footer"></div>
</div>
<!--if footer is here, footer works-->
</div>
</body>
I have two sticky elements the header
and footer
.
footer
doesn't work, but header
works, even footer and header are in same element.(they are sibling). Only top: 0
works correctly, but bottom: 0
works incorrectly.