Creating divs of the same height with CSS styling

I am struggling with making 3 floating <div>s all the same length within a wrapper. The issue is that they need to be responsive and cannot have fixed heights.

While researching on stackoverflow, I came across a post addressing this problem: Make floating divs the same height

Despite trying the solution proposed in the post, I couldn't get it to work properly. I even created a fiddle where the middle column has the most text, so ideally, the other two should match its height.

* {
  box-sizing: border-box;
  -webkit-box-sizing: border-box;
  /* Safari/Chrome, other WebKit */
  -moz-box-sizing: border-box;
  /* Firefox, other Gecko */
}
#iconWrapper {
  display: table;
  margin-top: 50px;
  height: 500px;
}
.icon {
  float: left;
  width: 33.3%;
  text-align: center;
}
.explanation {
  text-align: left;
  width: 90%;
  min-height: 200px;
  margin: 0 auto;
  margin-top: 40px;
  border-radius: 10px;
  padding: 20px;
  margin: 20px;
}
.boxOrange {
  border: 2px solid RGBa(213, 99, 42, .4);
}
.boxBeige {
  border: 2px solid RGBa(211, 200, 175, .4);
}
.boxGreen {
  border: 2px solid RGBa(137, 176, 185, .4);
}

JS FIDDLE: http://jsfiddle.net/Qv8ak/

Answer №1

Try using display:table-cell; for your .icon class and applying height:100% to .explanation

Check out the example on jsFiddle

.icon {
    display:table-cell;
    height: 100%;  /* Adjusted for Firefox compatibility */
    width:33.3%;
    text-align:center;
}
.explanation {
    text-align:left;
    width:90%;
    height: 100%;
    margin: 0 auto;
    margin-top:40px;
    border-radius:10px;
    padding:20px;
    margin:20px;
}

Answer №2

The problem lies in your .icon class floating left, causing the issue. To fix this, you should add "display: table-cell;" to your .explanation class.

Best of luck with resolving the issue!

I made changes to your fiddle here: http://jsfiddle.net/Qv8ak/10/

.explanation {
    display: table-cell;
}

Apologies for the incomplete answer - I'm still learning!

UPDATE: I have updated the fiddle link to address the concerns mentioned in the comments.

For more information, check out:

Answer №3

In order to achieve the desired layout, make sure to include display: table-cell in the styling for .icon, as well as height:100% for both .icon and .explanation.

For a visual demonstration, refer to this jsFiddle link

Answer №4

If you come across this question in the future, and browser compatibility with older versions is not a concern, you can make columns of equal height using CSS3 flexbox.

All you need to do is add display:flex to the parent element:

* {
  box-sizing: border-box;
  -webkit-box-sizing: border-box;
  /* Safari/Chrome, other WebKit */
  -moz-box-sizing: border-box;
  /* Firefox, other Gecko */
}
#iconWrapper {
  display: flex;
  margin-top: 50px;
}
.icon {
  display: flex;
  width: 33.3%;
  text-align: center;
}
.icon::after {
  clear: both;
}
.explanation {
  text-align: left;
  width: 90%;
  min-height: 200px;
  margin: 0 auto;
  margin-top: 40px;
  border-radius: 10px;
  padding: 20px;
  margin: 20px;
}
.boxOrange {
  border: 2px solid RGBa(213, 99, 42, .4);
}
.boxBeige {
  border: 2px solid RGBa(211, 200, 175, .4);
}
.boxGreen {
  border: 2px solid RGBa(137, 176, 185, .4);
}
<div id="iconWrapper">
  <div class="icon">

    <div class="explanation boxGreen">
      <img src="img/icon3.png" />
      <h2 class="green">IT Support</h2>

      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam ullamcorper dictum rutrum. Donec at dolor gravida, egestas magna non, egestas sem. Sed id massa ac lacus faucibus gravida sed nec nulla. Nam enim nisl.</p>
    </div>
  </div>
  <div class="icon">

    <div class="explanation boxOrange">
      <img src="img/icon1.png" />
      <h2 class="orange">Communications</h2>

      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam ullamcorper dictum rutrum. Donec at dolor gravida, egestas magna non, egestas sem. Sed id massa ac lacus faucibus gravida sed nec nulla. Nam enim nisl. Lorem ipsum dolor sit amet,
        consectetur adipiscing elit. Aliquam ullamcorper dictum rutrum. Donec at dolor gravida, egestas magna non, egestas sem. Sed id massa ac lacus faucibus gravida sed nec nulla. Nam enim nisl.</p>
    </div>
  </div>
  <div class="icon">

    <div class="explanation boxBeige">
      <img src="img/icon2.png" />
      <h2 class="beige">Cloud Solutions</h2>

      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam ullamcorper dictum rutrum. Donec at dolor gravida, egestas magna non, egestas sem. Sed id massa ac lacus faucibus gravida sed nec nulla. Nam enim nisl.</p>
    </div>
  </div>
</div>

Link to JSFiddle

Note: To achieve the same layout as described in this question, some slight markup changes will be needed. I recommend exploring the use of flex for layouts, rather than relying on float. It's time to utilize float for its intended purpose :)

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

JavaScript providing inaccurate height measurement for an element

Upon loading the page, I am trying to store the height of an element. To achieve this, I have utilized the jQuery "ready" function to establish a callback: var h_top; var h_what; var h_nav; $(".people").ready(function() { h_top = $(".to ...

Embracing right-to-left (RTL) languages

I am looking to create a website that can support both left-to-right (LTR) and right-to-left (RTL) languages seamlessly. My goal is to have the text direction switch automatically to RTL if the content is in an RTL language. Additionally, I want the input ...

"Trouble arose when I tried to incorporate additional functions into my JavaScript code; my prompt feature is not

As a beginner in HTML and JS coding, I am working on creating a page that prompts user input for a name and then executes animations using radio buttons. However, after adding functions for radio button changes, my prompt is no longer functioning properly. ...

Having trouble removing lines from Router Link? Unfortunately, using style={{'textDecoration': 'none'}} doesn't seem to be doing the trick

Does anyone know why the text decoration is not working on my link when I use text-decoration none? Any solutions or suggestions would be greatly appreciated. Thank you in advance! Navbar.js file import React,{useState} from "react"; import { mak ...

The tab component is failing to load due to an issue with the Bootstrap tab

I've created a page displaying different locations with two tabs - one for Google Maps and another for weather. For example, take a look at this location: The issue I'm facing is that when switching between the tabs, they don't load fully. ...

Using CSS to conceal an element when a different element is also invisible

My inquiry is as follows: I currently possess a code that conceals class element 1 when it possesses a specific value (which varies across different sites). Now, my objective is to also conceal class element 2 ONLY IF class element 1 is already hidden. ...

Styles in print CSS are not effective in an Angular project

Currently, I am working on an Angular project where I need to generate a printable document using CSS. The challenge I am facing is ensuring that the date and title in the header do not print automatically when the document spans multiple pages. Additional ...

Enhance the serialization with more information when submitting

I'm trying to submit form data along with some extra information using serializeArray, but for some reason it's not working as expected. $("#submitBtn").submit(function(ev) { ev.preventDefault(); var info = $(this).serializeArray(); info ...

Utilizing Regular Expressions to remove specific CSS attributes from an HTML content

I'm facing a challenge with my telerik RadEditor where users can input HTML that gets saved to my database. While this usually works well, I encounter issues when the CSS attributes position: absolute; or z-index: 100; (any # for z-index) are present ...

Organize icons within a container that spans the entire height

I am looking to organize multiple icons within a container that spans the entire height of the website, rather than just the viewport. Currently, I am only able to achieve the height of the viewport using the following code: .full-container { posit ...

Transferring JSON data from Django for visualization on a D3 graph

I'm currently working on customizing a D3 bar graph found at http://bl.ocks.org/3885304 to accommodate JSON data from Django. In Django, I have a variable that holds JSON formatted data like this: [{"score": 1, "color": "blue"}, {"score": 5, "color": ...

Obtain the state name after selecting it from the drop-down menu and clicking the submit button (part 3)

Read more about passing city names from PHP to JS in the second part of this discussion on Stack Overflow. This is the JSON data for states ($stateJsonObject): Array ( [0] => stdClass Object ( [stateId] => s1 [stateName] => Kuala Lumpur) ...

What is the best way to split two divs in this manner?

Is there a way to split two divs like this in such a manner using TailwindCSS? Alternatively, what would be the CSS code for dividing these two divs? I am struggling with this concept and cannot wrap my head around how it can possibly be achieved. ...

Understanding the distinction between assigning a value and setting text through JSE in Selenium using C#

Utilizing the IJavaScriptExecutor to set the attribute value can sometimes result in the text box containing the set value, but not displaying it as text. In some cases, the input is sent normally to certain text boxes, while for others, it is only setting ...

How can an HTML5 application be configured to enable access to intranet and local files?

It's a known fact that accessing the local path of a file added using a file input field or drag-and-drop is not possible even with the new FileAPI. Whether this limitation is good, bad, or ugly is not up for debate. The FileAPI specs clearly state th ...

Error during compilation due to a missing parenthesis in the loop structure

I've been experimenting with creating a carousel using just html and css, without any Javascript. I've been exploring resources on the web and following tutorials to achieve this goal. However, I've encountered an issue. I created a mixin l ...

Hover over the text below to see an image appear in its place

I'm looking to swap out some text with an image when hovering over it, using basic HTML/CSS. NO: show the image below the text NO: display the text on top of the image NO: replace one image with another YES: replace the text with an image ...

Is it possible to extract tooltip text from a website using Python and Selenium, specifically when the text is generated by JavaScript?

Can anyone help me retrieve the tooltip text that appears when I hover over the time indicating how long ago a game was played? You can find my summoner profile here. I have noticed that the tooltip text is not visible in the HTML code and suspect it may ...

Ensuring input boxes are neatly positioned underneath one another, regardless of the chosen font size

Is there a way in CSS to ensure that these input boxes are always aligned below each other, regardless of font family, size, or window movement by the user? https://i.stack.imgur.com/Zbadh.png Currently, I am using the following approach: tab1 { paddi ...

Tips for showing all percentages on a Google PieChart

I'm currently encountering two issues. How can I ensure that the entire legend is visible below the graph? Sometimes, when the legend is too large, three dots are added at the end. Another problem I am facing involves pie charts. Is there a way to d ...