Sibling div positioned below the main div

I have a container div with two child divs inside. The first child div has a fixed width, but its height depends on the content (a message box). Right next to it on the same line, I want another div (displaying the time) to be at the bottom of the parent div, aligned with the lowest line of the message in the first child div.

I'm looking to achieve something like this:

Do you see how the time is positioned next to the message?

In order to accomplish this, I believe I should make the time div the size of the parent div. How do I go about achieving that?

Thank you for your help in advance!

This is the HTML structure:

<div class="yellowmessage">
    <div class="themessage">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod</div>
    <div class="dateandtime">11:37AM</div>
</div>

And here is the corresponding CSS:

.yellowmessage { /* Parent div */
    padding:0 2% 0 0;
    float:left;
}

.themessage {
    font-size:2.5em;
    display: inline-block;
    border-radius:20px;
    padding:3% 0 3% 0;
    max-width:90%;
    background-color:rgb(246,227,143);
    float:left;
}

.dateandtime {
    float:left;
}

Answer №1

This resource provides a solution to your query, giving you the answer you seek here.

Furthermore, I have made some tweaks and enhancements to improve the functionality.

Check out the live demonstration at

**http://jsfiddle.net/mek5Z/1348/**

Answer №2

Fiddle

If your HTML structure looks something like this:

<div class="redmessage clear">
    <div class="messagetext">
        <p contenteditable="true">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
    </div>
    <div class="timestamp">1:23PM</div>
</div>
<div class="greenmessage clear">
    <div class="messagetext">
        <p contenteditable="true">Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</p>
    </div>
    <div class="timestamp">2:45PM</div>
</div>

You can style it using this CSS:

.redmessage, .greenmessage {
    position: relative;
    margin: 5% 2%;
}
.messagetext {
    font-size:1.5em;
    border-radius:15px;
    padding: 0 2%;
    max-width: 80%;
    box-shadow: inset 0 -4px rgba(0, 0, 0, 0.05), inset 0 18px 20px rgba(255, 255, 255, 0.5), 0 2px 9px rgba(0, 0, 0, 0.25);
}
.redmessage > .messagetext {
    float: left;
    background-color: #FFC0CB;
}
.greenmessage > .messagetext {
    float: right;
    background-color: #90EE90;
}
.timestamp {
    position: absolute;
    bottom: 0;
    font-size: 75%;
}
.greenmessage > .timestamp {
    left: 0;
}
.redmessage > .timestamp {
    right: 0;
}

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

The height of the div element is automatically adjusted to zero

I am dealing with a simple layout where I have a main div that floats to the left. Within this main div, I nest other divs using the clear both style. Below is a simplified version of my setup: <div id="wrapper" class="floatLeft"> <div id="ma ...

Understanding the purpose of the notched property in Material-UI

I am currently integrating Material-UI into a project and exploring their API. One thing that I find confusing is the notched property within the OutlineInput Component. <FormControl variant='outlined'> <OutlinedInput notched={false} ...

Attempting to incorporate every item from a for loop into an array using JavaScript

I have an index.html file containing a display of a mySQL table: <body> <div class="container"> <table align="center"> <tr> <th bgcolor="#f0a00c">Col1</th> <th bgcolor="#f0a00 ...

Capture and reroute the loading of stylesheets, images, and fonts coming from Gecko

Seeking guidance for a C# application utilizing geckofx. I am looking to intercept and redirect the loading of images, fonts, and style sheets. My goal is to potentially load these resources from a database. I've experimented with SetParentURIContentL ...

Assign individual heights to multiple iFrames according to their content's height

Dealing with multiple iframes on a single page. Each iframe is sourced from my domain. The goal is to automatically calculate and set the height of each iframe on the page. The current code sets all iframe heights to match that of a specific iframe: fun ...

Mirror the image horizontally prior to saving

I'm working on a camera web app that has filters similar to Snapchat. I'm currently facing an issue where the image is mirrored because I'm using the front camera. Is there a way to flip the image before downloading it? Thank you for your re ...

Is there a way to customize the design of the "Browse" button within the HTML file upload control?

I've been searching high and low on the internet for a simple, sleek method to customize the appearance of the Browse button on an HTML <input type=file> element. However, all the solutions I've come across involve hiding controls, placing ...

Database query is failing to return any results

Currently, I am developing a URL shortener system which involves storing data in my database such as an id, url, code, and created. However, I encountered an issue where the code does not return the required code despite checking if the entered url exists. ...

JS-powered menu links losing color after being clicked

I have a JavaScript rollover switch issue - when I click on the link, the color should stay orange (#f7931d), but it reverts back to grey. What am I missing in my code? CSS: #content-slider { padding-top:5px; height: 240px; width: 359px; ...

Icons on Google Calendar events - Mini images beside your schedule

I'm in the process of developing a website where I plan to integrate Google Calendar. I want to include a small icon next to specific events to denote certain details. While the "categories" feature in Google Calendar allows me to assign highlight col ...

Set default values for input fields based on selected options in php and mysql

I need help creating a form that will submit details when an option is selected from a database. The MySQL table has the following fields under USERS : [email], [age], [name]. I want to automatically fill in the values of other input fields when a user s ...

Converting XPath into CSS

I really need your assistance in converting XPath to CSS. I have this code snippet and XPath expression: /descendant::p/parent::*/child::p[position()=1] ... The selected elements will be (B D F H) <?xml version="1.0" ?> <book> <title&g ...

The "a" HTML link element is stubbornly resisting being attached to an event listener

I have implemented the MutationObserver observer in my program to monitor the addition of elements. One specific condition I am checking for is if the added element is an anchor tag (tag="a") and if the link is a DOI, then I attach a contextmenu ...

Issues with aligning center vertically and horizontally using flexbox are causing unexpected behavior

Understanding the basic concepts of centering a flex container using justify-content:center and align-items: center, I am facing an alignment issue with my box. Can anyone help me with this? This is what I have attempted so far: <template> <di ...

What is the best way to retrieve data from a database and display it in a select dropdown list

I'm working on creating a Bingo game and I want to include a dropdown list that displays my previous records. How can I retrieve data from a database to populate this select dropdown list? Below is the relevant code snippet in PHP: <html> < ...

Employing IF conditions within a form to refine options

I am looking to streamline the options in my form based on the car and transmission selected. I have set up the form, but I am struggling with the JavaScript code. I need help figuring out how to only display certain color options when Car 1 is chosen alon ...

How to Arrange Information Harvested from While and For Loops?

I am attempting to display the posts of a user's friends, similar to the layout of Facebook's main page. Currently, to echo out a user's friend's posts, the database table for that user contains a reference to a text file. In my case, t ...

Tips on keeping an HTML element from shifting when resizing the browser window (how to lock an element in a specific position on a webpage)

As a newcomer to front-end web development, I recently attempted creating a basic responsive page. While working on this project, I encountered an issue with the candle holder image. This image is size-responsive, meaning it adjusts in size as the browser ...

Turn off all the styles associated with a specific CSS selector

Looking for a solution to override CSS rules for the .lp-caption selector? .lp-caption { -moz-border-bottom-colors: none; -moz-border-left-colors: none; -moz-border-right-colors: none; -moz-border-top-colors: none; backgr ...

Utilizing JQuery slideToggle() to Toggle Between Opening and Closing Multiple Divs

Utilizing Jquery's slideToggle() function to manage the opening and closing of my main menu has been a success. However, I am facing the challenge of making sure that when one div is opened, another one closes. Despite trying various methods, I have ...