My goal is to show a continuous console output on a webpage.
The container that holds the output has a maximum height. Every new line gets added to the bottom. Now I want the last line to always be visible for the user (unless he scrolls himself, then the scrollbar should not jump back, when a new line is added).
I tried to do that with CSS and while it works fine within chrome, it does not within Firefox:
jQuery(document).ready(function($) {
window.setInterval(function() {
$('.log').append('<div class="line">Lorem ipsum dolor sit amet</div>');
}, 100);
});
.window {
height: 300px;
background: #fff;
}
.log {
background-color: #1c1c1c;
margin-top: 0;
margin-bottom: 0;
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace;
font-size: 12px;
padding: 16px;
overflow: auto;
line-height: 1.45;
border-radius: 3px;
white-space: pre-wrap;
overflow-wrap: break-word;
color: #DDD;
}
.log-container {
flex-basis: 100%;
}
.autoscroll {
flex-basis: auto;
display: flex;
flex-direction: column-reverse;
height: calc(100% - 56px);
overflow-y: auto;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="window">
<h4>Show Logs</h4>
<div class="autoscroll">
<div class="log-container">
<pre class="log"></pre>
</div>
</div>
</div>
(fiddle)
Does anybody have any idea how I can get this working reliably on all browsers?
Edit: It's not a duplicate of this question, as I want a css solution and not a javascript solution (if possible). It almost works, but sadly not yet within firefox.