[Answered ]-How do I fix the scrollbar to always be at the bottom using tailwind css?

1๐Ÿ‘

โœ…

enter image description here

Try this :

const chatBox = document.getElementById('chatBox');

// Function to scroll the chat box to the bottom
function scrollToBottom() {
chatBox.scrollTop = chatBox.scrollHeight;
}

window.onload = scrollToBottom;


<div class="overflow-auto" id="chatBox">

</div>

If you want to only use Tailwind CSS you can try this :

<div class="overflow-auto h-96 scroll-snap-y-container">
<!-- Empty element to push content down -->
<div class="flex h-0 w-0">.</div>

<!-- Your chat message divs will be appended here -->

<!-- Empty element to create space at the bottom -->
<div class="flex h-0 w-0">.</div>
</div>

Note : You can adjust the h-96 class to control the height of your chat box.

๐Ÿ‘คJayesh Cholkar

Leave a comment