Is it possible to have 3 divs with the height of the tallest

I have a unique template that I employ for crafting responsive websites. It relies on boxes with percentage widths, floats, and clears. A prime instance can be viewed via this link. Notice how the three boxes vary in height. While it's simple to set a fixed height, problems arise when the content extends beyond causing one box to grow larger than others.

Is there a straightforward approach to make all three boxes match the height of the tallest div?

Find below the CSS pertaining to the boxes and the media query.

.clear{clear:both;}
.box{float:left; margin:1%; padding:1.5%; background:#6f0100;}
.box p.small{font-size:1.1em; margin-bottom:7px;}

... (CSS continued)

Your insight on this matter is greatly appreciated. Thank you.

Answer №1

Check out the DEMO Give this method a try to achieve equal height columns

CSS:

.box {
    display:table;
}
.row {
    display:table-row;
}
.row div {
    display:table-cell;
    background-color:#ccc;
}

HTML

<div class="box">
    <div class="row">
        <div class="one"></div>
        <div class="two"></div>
        <div class="three"></div>
    </div>
 </div>

Answer №2

If you're searching for a jQuery solution, here is an example of how it can be implemented:

var elements=$('.elements');
$.each(elements, function() {
    var maxHeight = 0;
    $.each($(this).find('.item'), function() {
        if($(this).height() > maxHeight)
            maxHeight = $(this).height();
    });
    $.each($(this).find('.item'), function() {
        $(this).height(maxHeight);
    });
});

Answer №3

If you're not concerned with ancient browser support, you have the option to create equal height columns using pure CSS with the help of CSS3 flexboxes.

For instance:

HTML

<section id="container">
  <div class="column"></div>
  <div class="column">
    <p>Lorem ipsum ... elit.</p>
  </div>
  <div class="column"></div>
</section>

CSS

#container {
display: flex;
}
.column {
width: 33.3%;
}

Live Demo

Explore more about flexboxes on CSSTricks

Answer №4

Here is the updated CSS code that you can replace in your existing stylesheet. Feel free to test it out on this DEMO.

Important: Make sure to only modify these specific lines.

.row{display:table; border-spacing: 20px;}
.box {background:#6f0100; margin: 1%; padding: 1.5%; display:table-cell;}

Answer №5

Include the below css styles

#allcontent .row {
    display: flex;
}
.box.box33 {
    flex: 1;
}

Answer №6

Utilize the flexbox property to control layout.

See an example here

.container {
  display: flex;
}

.container div {
  border: 1px solid blue;
  padding: 20px;
}

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

Creating an input field within a basic jQuery dialog box is not possible

Can anyone assist me in adding an input box to my dialog box? I am working with jquery-ui.js. Here is the code I currently have: $(document).on("click",".savebtn",function(). { var id = $(this).attr("id"); $.dialog({ ...

Creating an unsorted list from information in a database table: A step-by-step guide

Hello, I am currently working on populating an unordered list with data from a SQL Server 2005 table. The table contains information about various applications like home, organization (with children such as policy and employee details), recruitment, help, ...

Convert string query into an array in PHP containing keys and values

When passing the given query string into a PHP method searchFilterKeyword=ff&searchFilterDateEntered=07%2F29%2F2019&searchFilterStatus=1&searchFilterQuarantineStatus=&searchFilterSize=&searchFilterKennel=&searchFilterType= How can ...

Tips for styling your Angular Material Card on mobile devices

Currently, I am very happy with my desktop layout which looks like this: https://i.stack.imgur.com/tG0pw.png However, when it comes to the mobile version of my site, here is what I have so far: https://i.stack.imgur.com/KD1hh.jpg While I do like the ho ...

generate a customized synopsis for users without storing any data in the database

In order to provide a summary of the user's choices without saving them to the database, I want to display it in a modal that has already been created. Despite finding some sources online, none of them have worked for me so far. Below is my HTML: &l ...

Automatically populate the options of a dropdown menu using jQuery

I am a beginner in the world of Javascript, JSON, and jQuery. I am seeking some guidance as I navigate through this new territory. On my JSP page, there is a drop down list that needs to be populated with content when the page loads. To achieve this, I hav ...

Loading images in advance using JavaScript

I have been searching through multiple forums and cannot seem to figure out the issue. The problem I am encountering is related to a website where there are three images with a hover effect. When the page first loads, there is a delay in loading the backgr ...

What is the significance of vendor prefixes in the world of CSS3?

While I can see the rationale behind using prefixes for experimental non-official features to avoid conflicts, what is the reason for using them on shadows and similar elements? Shouldn't all vendors be implementing effects consistently according to ...

"Challenges Arising in Deciphering a Basic JSON Array

After countless attempts, I am still struggling to solve this issue. My PHP code is functioning properly, as it returns the expected data when "Grove Bow" is selected from the dropdown menu: [{"wtype":"Grove Bow","was":"1.55","wcc":"5","wbdmin":"12","wbdm ...

Code to execute function depending on the width of a div

Looking for a script that can run a function depending on the width of a div. I want the ability to trigger the function when the div is resized. For example, if the div's width is 300px, execute function 1; if it's 700px, execute another functi ...

The Double Trigger of Ajax Notifications

Can anyone help me figure out why the alert is firing twice? The code snippet involves a checkbox with the class .onoffswitch. <script type="text/javascript"> $(document).ready(function(){ $('.onoffswitch').click(function(){ ...

Tips for showing text beyond the confines of a <div></div> container

<div class="signup"> <div>Tenxian アカウントに必要な情報</div><br/> </div> <br/><br/><br/><br/><br/><br/> <div align="center">@2009 Tenxian &nbs ...

Is there a way to use jQuery to eliminate divs that contain multiple identical data values?

Is there a way to accomplish this? <div class="chat_timestamp_group" data-date="08-March-2016"></div> <div class="chat_timestamp_group" data-date="08-March-2016"></div> <div class="chat_timestamp_group" data-date="14-March-2016" ...

Displaying search results seamlessly on the same page without any need for reloading

I am looking to create a search engine that displays results without the need to refresh the page. I have come across using hash as a potential solution, but I don't have much knowledge about web programming. So far, with the help of tutorials, I have ...

jQuery import children into output

When inserting a div every nth-child and later calling the children of the parent, the jQuery inserted elements do not appear in this new list. How can I retrieve the inserted elements as well? Apologies if this is confusing. If it's easier to under ...

Utilize Selenium in Python to choose an element

When working with the following HTML code: <div class="nav-category__col" id="category_nav_level_3" style="display: block;"> <input type="hidden" value="1" name="videogame_type" id="videogame_type"> <ul class="nav-category__list" adp ...

using JavaScript to strip away content following .jpg

var lochash = "#http://www.thepresidiumschool.com/news_image/102%20NRD_7420.jpg&lg=1&slide=0"; I am looking to eliminate or modify the content that comes after .jpg. ...

What is the best way to use ajax to send a specific input value to a database from a pool of multiple input values

Welcome everyone! I'm diving into the world of creating a simple inventory ordering site, but am facing a roadblock with a particular issue: Imagine you have a certain number (n) of items in your inventory. Based on this number, I want to run a &apos ...

Place centered items within a flexbox that uses space-between alignment

When designing a navigation section, I am looking to achieve space-between justification. However, for smaller screens where the navigation items may need to wrap onto multiple rows, I want the items to center themselves instead of aligning to the left whe ...

Unexpected Results from WordPress Ajax Request

Currently, I am utilizing the snippets plugin in conjunction with Elementor. To implement an ajax function as a snippet, I have set it up like so: add_action( 'wp_ajax_get_slug_from_id', 'get_slug_from_id' ); add_action( 'wp_ajax_n ...