Designing three div containers of equal width without any elements being obscured

I currently have three widgets, each containing text of varying lengths. My goal is to ensure that all widgets are the same length, matching the longest text length among them.

Specifically, I want the blue and green widgets to extend in length to accommodate their text content. It's important that none of the content gets cut off or hidden behind the background.

How can I achieve this layout?

.first {width: 24%;float:left; padding:5px; background: blue;}
.second {width: 24%; padding:5px;float:left; background: red;}
.third {width: 24%; padding:5px;float:left; background: green;}
<div class="first">This is text.This is text.This is text.This is text.This is text.This is text.</div>
<div class="second">This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.</div>
<div class="third">This is text.This is text.This is text.This is text.This is text.This is text.</div>

Answer №1

To create a flexible layout, consider using CSS3 flexboxes:

View Example Here

.parent {
    display: flex;
}
.parent > div {
    padding: 5px;
    width: 33.33%;
}

For browser compatibility information on flexboxes, visit this link.

.parent {
    display: flex;
}
.parent > div {
    padding: 5px;
    width: 33.33%;
}
.first {
    background: blue;
}
.second {
    background: red;
}
.third {
    background: green;
}
<div class="parent">
    <div class="first">This is some text.</div>
    <div class="second">This is some more text.</div>
    <div class="third">This is even more text.</div>
</div>


Alternatively, you can achieve a similar effect with CSS3 tables:

View Example Here

.parent {
    display: table;
}
.parent > div {
    padding: 5px;
    width: 33.33%;
    display: table-cell;
}

Find out about browser support for CSS3 tables here.

.parent {
    display: table;
}
.parent > div {
    padding: 5px;
    width: 33.33%;
    display: table-cell;
}
.first {
    background: blue;
}
.second {
    background: red;
}
.third {
    background: green;
}
<div class="parent">
    <div class="first">Some sample text here.</div>
    <div class="second">More sample text goes in this section.</div>
    <div class="third">Additional text to demonstrate the layout.</div>
</div>

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

What is the best way to ensure that content fills the entire screen?

My goal is to position the footer at the bottom of the page. This is the initial code I tried: <html> <head> <title>Freds Cars, Trucks & Jeeps</title> <style> #container{ height: auto; ...

Displaying text on hover and showing a text box when a link is clicked using CSS and JavaScript

Hovering over the text will display "Edit," and clicking on it will reveal a text box. This function will be used to update content using ajax. HTML: <table> <thead> <tr> <th> Name </th> <th> Age </th> ...

Customized Quick Access MUI

Hey there! I'm currently working with the Speed ​​dial component for MUI and I'm having trouble figuring out how to style the tooltipTytle. I can only seem to style them when they are all displayed at once, but that's not what I want. I ...

Adjust the background of a CSS element using jQuery as the y-axis scroll crosses a specific threshold

Once the user has scrolled 600px down the page, I want a CSS background image to transition from no image to a specific background image (image 1). However, if they scroll above 600px, I want it to switch to another image (image 2). It should be able to co ...

Hover over the first element to remove its class and replace it with a different element

I am attempting to develop a function that adds the class = "actived" to the first Element. This class has a CSS style that highlights the element in question. I have a list of 4 lines and I want the first one to automatically receive this class, while t ...

Implementing Multiple Shared Footers in Rails 3

Looking for a solution to display unique footers in Rails? For instance, displaying one footer on the homepage and another footer on the rest of the site. Has anyone successfully implemented this before? I was considering using an if statement based on th ...

Toggle the backgroundImage visibility by setting it to either hidden or displayed using jquery

$('.arrow').css("background-image", "url('../img/arrow.png')").hide(); I have implemented a custom solution using CSS and jQuery to hide the downward arrow when scrolling down on my webpage. `$( document ).ready(function() {
 co ...

Designing a custom HTML calendar

I am currently working on a school project where I am creating a calendar using HTML. So far, I have set up the basic structure of the page. What I want to achieve is a functional calendar where users can create appointments that will be displayed accordi ...

What is the best way to initially hide a div using slide toggle and then reveal it upon clicking?

Is there a way to initially hide the div tag and then animate it in a slide toggle effect? I attempted using display:none on my '.accordion_box' followed by show() in slideToggle, but this results in adding the CSS property display: block. My goa ...

Div not growing to accommodate images

I've attempted to use the overflow:hidden; property, but it didn't have the desired effect. Essentially, my div is structured like this, and when I add more images, it doesn't expand along with them. This is how the div appears: https:// ...

Every time I make changes to the page, the outdated CSS keeps reappearing

I recently updated the CSS for React CKEditor 4 on my website to give it a better look. The changes were reflected when I first viewed the page on localhost, but strangely, when I go to another page with CKEditor 4, it reverts back to the original stylin ...

Creating a responsive layout with Bootstrap4 to show two rows of three columns on smaller screens

I am looking to design a pagination feature that has the following appearance: On a wide screen: | | | [<<] Page # 1 of 6 [>>] | | ...

What is the best way to embed an image into HTML code?

I am trying to enhance the appearance of a phone number inside an HTML code that is loaded into a UIWebView by adding a background image. NSString *stringToReplace = [NSString stringWithFormat:@"<a style=\"color:white; background-color:#707070; te ...

Material Design Angular2 Toolbar

I am currently working on designing a toolbar using Material and Angular2. My main challenge is formatting the toolbar in such a way that the search bar appears centered in white, while the "Create Project" button and other buttons are aligned to the right ...

Place two pictures in the center of a div container

Here is a div setup that I am working with: <div id="browsers"> <h2>Title</h2> <p>Text recommending the use of either Chrome or Firefox.</p> <a href="http://google.com/chrome/"><img src="img/64-chrome.png" /> ...

Utilizing JavaScript to arrange the dots around the circle proves to be glitchy

I am having trouble positioning dots around a circle. The top and bottom points are not aligning properly, resulting in a buggy display. What could be causing this issue? How can I fix this problem? $(function(){ var globe = $('#center') ...

Troubleshooting issue: Bootstrap not loading with custom CSS on Flask platform

Recently, I started learning Flask and created a basic web application. Utilizing Bootstrap 5 for my project, I encountered an issue where my custom CSS fails to work when the Bootstrap stylesheet is loaded (removing it resolves the problem). My folder st ...

Elements with a lower z-index do not have text drawn over them

I am currently facing an issue with a hidden list on a page that is crucial for my menu. Despite setting the z-index of different elements, the text inside a specific div only displays to one side which is causing alignment issues. Using display:none is no ...

Display SVG at full size without any distortion

How can I make the SVG image 100% by 100% without scaling? I want the image to be centered on the page both horizontally and vertically. The challenge is that I also want to display the areas outside of the SVG artboard, so using CSS to center it won&apos ...

Adjusting the spacing between a pair of radio buttons within the identical group

Is there a way to adjust the spacing between two horizontal radio buttons? The buttons are part of the same group, and I want to shift the right button ("Clear Selection") further to the right so it aligns with the buttons in another group below. ...