Struggling to position the newest messages at the bottom of the list

I'm working on creating a web chat system similar to IRC where the latest messages should always be at the bottom of the chat window.

Below is my attempt, but unfortunately it's not working as expected:

Content
Content
Content
Content
Content
Content
Content
The latest message that needs to be in the bottom

The div with msg-id="144" must be visible and positioned at the bottom.

Answer №1

Solution Enhanced by jQuery

Utilizing the HTML structure provided:

<div class='inner-conversation-container'>
    <div class='conversation-stream-container'>
        <!-- Single item example -->
        <div class='conversation-item'>
            <!-- Message elements -->
            <div class='conversation-message-part' msg-id='125'>
                <div class='center-part'>test 9</div>
            </div>

            ...

            <div class='conversation-message-part' msg-id='143'>
                <div class='center-part'>no, it&#x27;s not</div>
            </div>
            <div class='conversation-message-part' msg-id='144'>
                <div class='center-part'>latest needs to be in the bottom</div>
            </div>
        </div>
    </div>
</div>

Streamlined CSS for easier styling:

.inner-conversation-container {
    height: 200px;
    width: 500px;
    border: 2px solid lightgray; /* demo purposes */
    overflow: auto;
}
.conversation-stream-container {
    background-color: yellow; /* demo purposes */
}

jQuery used to adjust scroll bar position:

$('.inner-conversation-container').scrollTop(
   $('.inner-conversation-container')[0].scrollHeight
);

Check out this Live demo: http://jsfiddle.net/audetwebdesign/FW6Y5/

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Guide on selecting a <a>class within a table using Selenium for calendar interactions

My current setup involves working with 'Selenium2(WebDriver)' in Eclipse using Java. I'm trying to figure out how to click on a specific date within a table (Calendar). The issue I am facing is that every time I change the month in the cal ...

Guide to positioning a top navigation menu with dropdown items in the center using CSS: absolute positioning

I have implemented a pure CSS menu from this source on my website. It functions properly in the 'hamburger menu' mode, but I am encountering difficulties when attempting to center or right-align the menu in other modes. Despite trying various so ...

Saving an Image from HTML5 <canvas> using Java Servlet

Despite the numerous StackOverflow questions on this topic, I have gone through many of them without success. Now, I am reaching out with my own question. My objective is to save an image from an HTML5 <canvas> on my webpage to a file on my server u ...

Finding image input loading

When working with the following code: <input type="image" ... onLoad="this.style.opacity = 1" /> Everything seemed to be functioning well in IE, but encountered an issue in Chrome where the onLoad event failed to trigger upon image load. It's ...

The value within the style.setProperty function does not get applied

I have a progress bar that dynamically increases based on user input: <div class="progressBarContainer percentBar"> <div class="progressBarPercent" style="--width:${gPercent}" id="${gName}-pbar">< ...

When you click, a new webpage opens within my website, similar to the feature on Facebook

When using Facebook on mobile, clicking on a link to a person's website opens the website in front of the Facebook page. However, when users press the X in the top left corner, it deletes the webpage but keeps Facebook open. On my desktop computer, I ...

Ways to align text and horizontal rule perfectly within a div container?

I need to add some text to my <div> container and make sure it is centered. .hr { background: green; height: 50px; margin: 65px 0; width: 3000px; } <div class="hr"></div> This is an illustration of my project: https://i.sstatic.n ...

Is your Scrollmagic failing to function once your website is uploaded to the server?

My website incorporates Scrollmagic to dynamically load sections (changing opacity and adding movement) as users scroll through it. Everything functions perfectly fine when I preview the HTML file on my computer, but once I uploaded it to my hosting serv ...

How to create a see-through background using three.js

I am new to working with three.js and recently came across a codepen that caught my attention. However, I am facing difficulties while trying to change the background color. After exploring various questions related to this issue, I attempted to add { alp ...

How can I apply a specific style class to a table row when I already know the table's id?

Hi there! I'm new to jquery and trying to enhance the functionality of my application which has multiple HTML tables in JSP's. My goal is to use jQuery to dynamically apply a CSS style class when hovering over a row. Currently, I have the followi ...

PHP: the images uploaded are not located within the designated folder

Having trouble uploading multiple images to a folder and saving them in the database? The images are not moving to the folder, even though the code works on localhost. Here is the code snippet: var abc = 0; // Declaring and defining global incremen ...

How can you trigger a modal to appear when an image is clicked?

There are images inside <div> tags. When one of the images is clicked, a modal appears to display information about the specific image. Each modal has a unique id or class, such as modal4. My example: <image type="image" src="Images/Drake.jpg" ...

Square Division, width set to match 100% of the height

I have been attempting to create a square shape that is responsive, with the width determined by the height of the element (100%). I personally think achieving this using CSS alone is not possible. The goal is for the square's width to match its heig ...

Vue - making one element's width match another element's width

Trying to dynamically adjust the innermost element's width to match the outermost element's width with Vue: <div id="banner-container" class="row"> <div class="col-xs-12"> <div class="card mb-2"> <div ...

Troubleshooting: Difficulty with jQuery's resize event handler not functioning properly with

I'm currently facing an issue where I want a divider to adjust its size when another divider changes size due to new content being loaded into it. However, even after binding the resize event handler to the divider that loads the content, the event do ...

What is the best way to customize the appearance of the material-ui select component using styled-components instead of material-ui classes in a React

I've been facing some challenges while trying to style my material-ui select component using styled-components instead of material- classes. The version I am working with is material-ui/core 4.12.3. When I use the old makeStyles component from materi ...

Having trouble accessing the href attribute after clicking on an <a> tag with JavaScript

My issue lies in retrieving the href attribute of <a> tags when there is another element nested inside them: Here's the code snippet: const $elems = document.querySelectorAll('.content-container a') var elems = Array.from($elems) e ...

Tips for positioning a modal in the center specifically for zoomed-in mobile devices

I created a modal that uses the following function to center itself: center: function() { var top=Math.max($window.height() - $modal.outerHeight(),0) / 2; var left=Math.max($window.width() - $modal.outerWidth(),0) / 2; $modal.css({ ...

No adjustment in color upon switching themes

I've been struggling to achieve the desired outcome while working on a small coding task. The goal is to modify the color of the screen background, text, and button as illustrated in the uploaded image. I have three code files for this task - index, t ...

The optimal method for designing a select menu to ensure it works smoothly on various web browsers

Recently, I encountered an issue with customizing a select menu using CSS and jQuery. After some work, I was able to achieve a result that I am quite pleased with: So far, the styling works perfectly in Mozilla, Opera, Chrome, and IE7+. Below is the curr ...