What is the best way to right-align a flex column in Bootstrap 4 while ensuring they maintain equal height?

Learning the new Flex features in Bootstrap has been quite a journey for me. I must confess that I've had little experience with Flex before, especially since it wasn't well-supported in older versions.

If you're curious, here's a link to my CodePen showcasing what I've been working on:

http://codepen.io/youradds/pen/egLoVq

Essentially, my goal is to make all the columns equal in height while aligning the content at the bottom of each cell.

Here's a snippet of the code I'm currently using:

<div class="btn-group" data-toggle="buttons">
      <label class="btn btn-secondary align-self-end">
        <input type="checkbox" name="foo" class="checkbox" value="1" autocomplete="off" />
        Piscine
      </label>
      <label class="btn btn-secondary align-self-end">
        <input type="checkbox" name="foo" class="checkbox" value="1" autocomplete="off" />
        foo bar<br>
        foo bar<br>
        foo bar<br>
      </label>
      <label class="btn btn-secondary align-self-end">
        <input type="checkbox" name="foo" class="checkbox" value="1" autocomplete="off" />
        foo bar<br>
        foo bar<br>
      </label>
      <label class="btn btn-secondary align-self-end">
        <input type="checkbox" name="foo" class="checkbox" value="1" autocomplete="off" />
        foo bar<br>
        foo bar<br>
        foo bar<br>
        foo bar<br>
      </label>    
      <label class="btn btn-secondary align-self-end">
        <input type="checkbox" name="foo" class="checkbox" value="1" autocomplete="off" />
        foo bar<br>
        foo bar<br>
        foo bar<br>
      </label>    
</div>    

Despite my efforts, I still haven't been able to achieve uniform row heights as displayed below:

https://i.sstatic.net/p1wME.jpg

I've experimented with various approaches but nothing seems to work. Any suggestions or guidance would be greatly appreciated.

Answer №1

The Issue

In this scenario, there is a single flex container with the class div.btn-group

There are five flex items within this container, each with the class label.btn

To align these flex items at the bottom of the container, the Bootstrap class align-self-end is applied to each item.

However, using the align-self-end class causes the flex items to no longer stretch to the full height of the container because it overrides the default setting of align-self: stretch.

A Possible Fix

To resolve this, you can try the following:

  1. Remove the align-self-end class from all flex items. This will allow the default stretch behavior to take effect and the items will occupy the full height.

  2. Transform each flex item into a nested flex container.

  3. Apply align-items: flex-end to the new nested container.

By doing this, the main items will retain their full height while aligning the nested content (the actual text or buttons) to the bottom.

In essence, the solution involves removing the Bootstrap align-self-end class and adding the following CSS rule:

.btn {
  display: flex;
  align-items: flex-end;
}

Alternatively, in Bootstrap code, you can update each label element as follows:

<label class="btn btn-secondary d-flex align-items-end">

Check out the revised codepen here

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

Clicking on the images will display full page versions

Apologies for not making an attempt just yet, but I'm struggling to locate what I need. Here's the menu structure in question: <div class="overlay-navigation"> <nav role="navigation"> <ul class="test"> & ...

What is the process for incorporating a personalized SVG file into the material-ui Icon Component?

For my project, I have a requirement to use custom svg files. To achieve this, I am utilizing <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0865697c6d7a616964257d61483b2631263b">[email protected]</a>. I reviewed ...

Restriction on the number of characters displayed in div elements

Currently facing an issue where I need to display only the first 60 characters of a text (Description for Item) that users can see. Despite trying various solutions from stackoverflow, nothing seems to be working for me. Appreciate any help. Thank you. ...

Preserving the video's aspect ratio by limiting the width and height to a maximum of 100%

I am trying to integrate a YouTube video using their embed code in a "pop-up". However, I am facing an issue where the video does not resize to fit within the height of its parent. I want it to be constrained by the div#pop-up that contains the video. Curr ...

What is the best way to arrange three photos in columns of four each below one image spanning across all twelve columns?

Struggling with the bootstrap 5 grid? I'm trying to showcase one full image with a col-12 and 600px width, along with three images, each 200px wide with a col-4. The goal is to have one image on top and three beneath it with g-3 spacing between them. ...

Choose CSS Option

I need assistance with customizing my dropdown select option - see the example below <select> <option value="volvo" title="NEED THIS BIGGER AND FORMATED" >Volvo</option> <option value="saab">Saab</option> <option val ...

Ways to avoid overlapping between bootstrap columns

Currently, I am honing my skills in Bootstrap by creating a simple example with 3 columns of varying sizes: 2, 8, and 2. However, I have noticed that on certain screen sizes, the contents within these columns overlap each other. My goal is to prevent this ...

Ways to adjust the select element to match the width of its current option

As I work on building a form, I'm looking for a way to make the select element adjust its width based on the length of its current option. Essentially, I want the select element to expand or contract depending on the width of its longest option. I&ap ...

Is it possible to achieve knockout functionality with CSS binding through a function?

Here is functional code that uses Knockout to decide which color to use when rendering a state in the 2012 Presidential election. If the state value is 1 (Republican), it will be displayed in red. If the state value is 2 (Democrat), it will be displayed in ...

Turn off padding in material ui card

Currently, I am utilizing a material UI card and upon inspecting the card, I noticed the presence of this unique class: "MulticardContent-root". This class adds padding of 16 which I would like to remove. Strangely, it is not located within the styles co ...

Toggle visibility of cards using bootstrap

I've been attempting to show and hide a selection of cards in bootstrap, but I'm having trouble figuring it out. All the cards share the class "card," and my goal is to hide them all when a specific button is clicked. Below is my current code: ...

Is there a problem with using Nth-Child / Nth-Of-Type in CSS when classes are dynamically added or removed using jQuery?

Currently, I have a set of LI tags. As users filter the LIs, some may be removed from view. My goal is to assign alternating background colors to the visible LIs. When an LI is visible, it is given the class "LI-Shown." If an LI gets filtered out, I remov ...

Bring back object categories when pressing the previous button on Firefox

When working with a form, I start off with an input element that has the "unfilled" class. As the user fills out the form, I use dynamic code to remove this class. After the form is submitted, there is a redirect to another page. If I click the "back" ...

How can one element be made to rely on the presence of another element?

I'm currently working on my portfolio website and encountering an issue. Whenever I hover over an image of a project, the image expands in size, becomes less transparent, and a description of the project pops up. However, I would like to include a lin ...

Reorganizing the order of Bootstrap columns in a single row for mobile devices

I am struggling with changing the order of Bootstrap columns on smaller devices. I need them to remain in a single row on all screen sizes, but I want them to display in a different order on phones. Specifically, I want the layout to look like this on desk ...

Theming for Atom and Electron developer tools

After switching from the netbeans IDE to github's atom, I realized that some necessary features were missing. Unable to find a suitable package, I decided to try customizing it myself, gaining valuable insight into the editor in the process. However, ...

Title menu that can be both dragged and edited

I am currently working on developing an HTML user interface that enables my users to rearrange or organize the menu items or utilities according to their preference, much like the HOME screens on Android or iOS devices. I am seeking advice on how I can s ...

The navigation bar fails to respond when clicked on mobile devices

Calling all developers! I need a helping hand to tackle an issue that's holding me back from completing this website. Can someone please take a look at on their smartphone browser and figure out why the responsive menu icon isn't working when cl ...

The footer is not expanding to fill the entire width of the page

My footer is giving me trouble by not stretching to the full width on one specific page out of eight. This issue arose after I added an administration menu. Any assistance would be greatly appreciated. HTML: <div id="administraceMenu"> <ul clas ...

A surprise awaits in IE with the unusual appearance of a div display

body { background: #9cdcf9 url(/images/left_cloud.png) bottom left no-repeat; font-family:\"Trebuchet MS\"; padding:0; margin:0; border:0; } #cloud-container { width: 100%; background: url(/images/right_cloud.png) bott ...