Adjust the CSS to ensure that all elements have the height of the tallest element in the set

Can anyone help me solve a design issue I'm facing? I have a div with three floating buttons, but one of the buttons is taller than the others due to more content.

I'm looking for a way to ensure that all buttons are the same height as the tallest button. I attempted to use height: 100%;, but it didn't produce the desired result.

<!DOCTYPE html>
<html>

<head>
  <title></title>
  <meta charset="utf-8" />
  <style type="text/css">
    .container {
      width: 320px;
    }
    
    .container button {
      float: left;
      background: #FFFFFF;
      border: 1px solid #CCCCCC;
      width: 33.33%;
    }
  </style>
</head>

<body>
  <div class="container">
    <button>
                <span class="big-text">Okay</span>
                <span class="little-text">123</span>
            </button>
    <button>
                <span class="big-text">Another Option</span>
                <span class="little-text">456</span>
            </button>
    <button>
                <span class="big-text">Nah!</span>
                <span class="little-text">789</span>
            </button>
  </div>
</body>

</html>

https://jsfiddle.net/xpdxyaz6/1/

Answer №1

To achieve a flexible layout, simply include display:flex in your container class:

.container {
    width: 320px;
    display:flex;
}

You can view a working example on jsFiddle: https://jsfiddle.net/JohnDoe32/qwertyuiop/4/


Please Note:

Current browser compatibility for the Flex property as of May 2021 is outlined below:

Google Chrome: Partial support with prefix v4 - v20 | Full support with prefix v21 - v28 | Full support without prefix from version 29+

Mozilla Firefox: Partial support with prefix v2 - v21 | Partial support from v22 - v27 | Full Support starting from v28+

Internet Explorer: Partial support with prefix v10 | Partial support without prefix starting from v11+

Safari: Partial support with prefix v3.1 - v6 | Full support with prefix v6.1 - v8 | Full Support without prefix from version 9+

Edge: Fully supported starting from version 12+

Answer №2

Have you considered using the CSS property min-height? Check out the updated code in this fiddle link.

.wrapper {
   width: 320px;
}
.wrapper button {
   float: left;
   background: #FFFFFF;
   border: 1px solid #CCCCCC;
   width: 33.33%;
   min-height: 40px;
}
<div class="wrapper">
  <button>
    <span class="big-text">Yes</span>
    <span class="little-text">123</span>
  </button>
  <button>
    <span class="big-text">Another Choice</span>
    <span class="little-text">456</span>
  </button>
  <button>
    <span class="big-text">Not Interested</span>
    <span class="little-text">789</span>
  </button>
</div>

Answer №3

To achieve equal height for elements cross browser, you can utilize CSS rules such as padding-bottom: 999999em; and margin-bottom: -999999em; on the floated element. This will ensure consistent rendering of height across different web browsers. Additionally, remember to include an overflow: hidden on the parent element.

For a demonstration, please visit https://jsfiddle.net/xpdxyaz6/3/

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

Is there a disparity in how the mandatory field validator functions in Edge compared to Chrome?

There doesn't seem to be any red color How can I ensure consistency? Both elements should either have color or none at all. <form action=""> <input id="email" type="email" required="required" /> <input type="submit" id="btnS ...

What is the process for creating a new web page? [Exploring web design]

When creating a new page, how exactly does it work? For instance, on a website that allows users to create posts, you may see a link like this: example.com/post/randomised123 I'm curious - does this process also involve server directories like pop ...

Utilize AngularJS's nested ng-repeat to showcase information from two distinct JSON strings simultaneously

I am dealing with two different JSON strings from databases. [{ sport: football, sportid: 1 },{ sport: tennis, sportid: 2 },{ sport: golf, sportid: 3 },{ sport: swimming, sportid: 4 }] and [{ personid: 1, name: ...

Strange glitches and slow loading problems plaguing website. (GoDaddy)

TackEmporium.com Lately, I have been revamping my website, which was originally given to me by a friend. I have been making slight adjustments to update its appearance while keeping its classic look with enhanced resolution and cleaned-up HTML5 code. Rec ...

The functionality of the Bootstrap dropdown or radio input type is not functioning correctly

I'm currently utilizing electron([email protected]) along with bootstrap([email protected]). Whenever I attempt to incorporate a dropdown or other components from Bootstrap, they simply do not function. I am unsure of what mistake I might ha ...

Troubleshooting: :before element not being hidden by jQuery slidetoggle()

My elements are all behaving correctly with the slidetoggle() function, except for my li:before class. I've attempted to manipulate the overflow, visibility, display, and other properties of both the :before pseudo-element and the li element, but the ...

The element cannot be clicked at this point as another element would intercept the click:

Having an issue with clicking a button at the top of the page. The CSS selector works fine in my local Eclipse environment, but when trying to run it on Jenkins server on my local machine, it fails with an error stating that the element is not clickable. T ...

Using jQuery to dynamically render unordered lists from JSON data

Struggling to create a dynamic unordered list with multiple nested levels? Finding it difficult to render the necessary markup for future functionality? Take a look at the HTML structure I've created on this jsfiddle link: <ul class="nav nav-sideb ...

Is there a method to exclude children objects from spring animations during application?

Is it possible to create a fading in and out effect for a div (for example, to cycle through different backgrounds) while keeping its children (such as text) visible at full opacity at all times? {transitions((style, <animated.div class={ bg[i] + ...

Disable reloading when submitting and reset input fields after submission

I am working on developing a website where users can post things and comments without the need to refresh the page. I have encountered some issues while implementing this feature and need some assistance with it. My goal is to allow users to submit comment ...

What is the reason for the malfunction of input :: - webkit-slider-thumb and input :: - moz-slider-thumb?

Designing a compact slider for enhancing user experience not limited to webkit browsers requires utilizing a scss template such as input { width: 100%; -webkit-appearance: none; -moz-appearance: none; appearance: none; height: 1vm ...

Having trouble loading Yeoman Webapp SASS

Every time I try to build a web application using 'yo webapp', I encounter a 404 Error. GET http://localhost:9000/styles/main.css 404 (Not Found) I removed compass from the project, but that shouldn't be causing the issue, correct? ...

Tips on getting rid of the excess margin added by Android WebView printing

We have been attempting to print content from a webview via Google Cloud Print, but no matter what steps we take, the resulting printout always includes an unwanted margin. Is there a solution to eliminate this margin? We have tried: <body style="marg ...

The comparison between AJAX and JSON passing and PHP generating HTML versus returning it

Currently, my code looks like this: <li onclick = " function CBAppData( callerObj, data ) { var string = ''; for( a in data ) { debug.push( data[ ...

Binding event listeners to dynamically created elements poses a challenge

I am facing difficulty in adding an event listener to dynamically created elements. The issue lies in my code where I am unable to detect the insertion of <p> element resulting in the lack of console message Bar Inserted. Could you point out if there ...

When the screen size decreases, display the title on two lines

Currently, I am in the process of developing a react web application with the assistance of redux. My main objective is to ensure that the page is highly responsive. At this point, there is a title positioned at the top displaying: Actions to do: Past due ...

What advantages does using ImageMagick to resize images offer compared to using CSS?

My Ruby on Rails application has a feature that allows users to upload images. I have discovered that Active Storage can utilize ImageMagick to resize images using this code: model.image.variant(resize: "100X100") However, resizing images can also be ach ...

What is the best way to save an integer in HTML's localStorage instead of a string?

I've encountered an issue while using the localStorage feature in a game I'm developing. Specifically, the money variable should be increasing by 1 every second. Here's a snippet of my code: var money = 0; window.onload = function () { ...

Incorporating ASP includes within an HTML file

Is there a method to utilize ASP or ASP.NET for including HTML in another HTML file, similar to PHP includes with HTML and the AddType handler in .htaccess? I am exploring options for updating navigation on a Windows server that does not have PHP installe ...

Align several labels and text areas in the center

I am facing an issue with aligning multiple labels and textareas together. Currently, they line up like this: __________________ | | | | Label:|__________________| However, I want them to appear as fol ...