I would like to show users who load the site the bottom of the page and not — as normally — the top.
More specific example: I have an iframe element which points to a site with some text. The bottom of this site should automatically be shown.
How can I realize this?
Use flex
and its flex-direction: column-reverse;
html, body {
margin: 0;
}
.wrapper {
display: flex;
flex-direction: column-reverse;
max-height: 100vh;
overflow: auto;
}
<div class="wrapper">
Top<br><br><br>
Long content <br><br><br>
Long content <br><br><br>
Long content <br><br><br>
Long content <br><br><br>
Long content <br><br><br>
Long content <br><br><br>
Long content <br><br><br>
Long content <br><br><br>
Long content <br><br><br>
Long content <br><br><br>
Long content <br><br><br>
Long content <br><br><br>
Long content <br><br><br>
Long content <br><br><br>
Long content <br><br><br>
Long content <br><br><br>
Long content <br><br><br>
Bottom
</div>
Side note:
This solution seems to still has some flaws not work properly in Firefox/Edge/IE11 (they don't show the scroll bar, though content start at bottom), so here is a fix for them until they start behave
The below code snippet is taken and cleaned up from another answer of mine, at this post, where there are a few more options to handle this issue.
/* fix for IE/Edge/Firefox */
var isWebkit = ('WebkitAppearance' in document.documentElement.style);
var isEdge = ('-ms-accelerator' in document.documentElement.style);
function updateScroll(el){
el.scrollTop = el.scrollHeight;
}
if (!isWebkit || isEdge) {
updateScroll(document.querySelector('.content'));
}
html, body {
margin:0;
}
.wrapper {
display: flex;
flex-direction: column-reverse;
max-height: 100vh;
overflow: auto;
}
/* fix for hidden scrollbar in IE/Edge/Firefox */
.content { overflow: auto; }
@media screen and (-webkit-min-device-pixel-ratio:0) {
.content { overflow: visible; }
@supports (-ms-accelerator:true) { .content { overflow: auto; } }
}
<div class="wrapper">
<div class="content">
Top<br><br><br>
Long content <br><br><br>
Long content <br><br><br>
Long content <br><br><br>
Long content <br><br><br>
Long content <br><br><br>
Long content <br><br><br>
Long content <br><br><br>
Long content <br><br><br>
Long content <br><br><br>
Long content <br><br><br>
Long content <br><br><br>
Long content <br><br><br>
Long content <br><br><br>
Long content <br><br><br>
Long content <br><br><br>
Long content <br><br><br>
Long content <br><br><br>
Bottom
</div>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With