How do I ensure all columns have equal heights?

I have tried using flexbox, but the column heights are still not the same. I have looked at various methods on websites like W3Schools and Medium, but none of them seem to work. Initially, using the flex method worked, but it seems to be disappearing when I refresh the page. I am unsure why this is happening.

Can anyone please review this code and let me know if there is anything wrong with it? I would greatly appreciate any help with this issue.

<html>
<head>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
    <title>Bootstrap Page</title>
    <style>
        p{
            background:rgba(25,105,25,0.4);
            color:white;
         }
        .row{
            display: flex;
            flex-wrap: wrap;
        }
        .row > .col-md-6 {
            display: flex;
            flex-direction: column;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="row display-flex">
            <div class="col-md-6 para1">
                <div>
                    <p>M. Best who informed him that locomotives 
                       could be obtained at a railroad boneyard in Mérida, Yucatán, Mexico, owned by the Ferrocarriles Unidos de Y
                       ucatán..</p>
                </div>
            </div>
            <div class="col-md-6 para1">
                <div>
                    <p> Best who informed him that locomotives 
                            could be obtained at a railroad boneyard in mer, went to Mérida in 1969 to investigate.The development er, went to Mérida in 1969 to investigate.The developme
                        nt of the Walt Disney World Railroad from the late 1960s to its opening in 1971 was overseen by Roger E. Broggie,
                         vice president and general manager of Mapo, Inc</p> 
                </div>
            </div>
        </div>
    </div>
</body>

Answer №1

Here is a more organized version. Various colored borders have been added to the classes for better visualization of their interactions.

p {
  background-color: rgba(25, 105, 25, 0.4);
  color: white;
  border: 1px solid green;
  box-sizing: border-box;
  padding: 10px;
}

.container {
  border: 1px solid red;
}

.row {
  border: 1px solid blue;
}

.div {
  border: 1px solid orange;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<html>

<head>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
  <title>Bootstrap Page</title>

</head>

<body>
  <div class="container d-flex">
    <div class="row d-flex">
      <div class="col-6 d-flex align-items-stretch">
        <p>M. Best who informed him that locomotives could be obtained at a railroad boneyard in Mérida, Yucatán, Mexico, owned by the Ferrocarriles Unidos de Yucatán..
        </p>
      </div>
      <div class="col-6 d-flex align-items-stretch">
        <p> Best who informed him that locomotives could be obtained at a railroad boneyard in mer, went to Mérida in 1969 to investigate.The development er, went to Mérida in 1969 to investigate.The development of the Walt Disney World Railroad from the
          late 1960s to its opening in 1971 was overseen by Roger E. Broggie, vice president and general manager of Mapo, Inc
       </p>
      </div>
    </div>
  </div>
</body>

Answer №2

It appears that your code is functioning correctly, although the .col-md-6 elements are equal in height, not the p.

To address this issue, you can remove the background-color from the p and include the following CSS:

.col-md-6 > div {
    height: 100%;
    background:rgba(25,105,25,0.4);
}

https://jsfiddle.net/q2tteygo/4/

Answer №3

Here is a snippet from my personal code that you may find helpful. It is located in an external CSS file rather than within a "style" section. This code applies styling to UL elements displayed in columns with borders around them:

@import url('https://fonts.googleapis.com/css?family=Open+Sans:400,400italic,600,600italic,700,700italic,800,800italic');
@mixin flexbox() {
  display: -webkit-box;
  display: -moz-box;
  display: -ms-flexbox;
  display: -webkit-flex;
  display: flex;
}

@mixin flex($values) {
  -webkit-box-flex: $values;
  -moz-box-flex:  $values;
  -webkit-flex:  $values;
  -ms-flex:  $values;
  flex:  $values;
}

@mixin order($val) {
  -webkit-box-ordinal-group: $val;  
  -moz-box-ordinal-group: $val;     
  -ms-flex-order: $val;     
  -webkit-order: $val;  
  order: $val;
}

body {
    font-family: 'Open Sans', sans-serif;
    padding-bottom: 2em;
    @include flexbox();
}

/* https://css-tricks.com/snippets/css/a-guide-to-flexbox/ */
li.columns {
    @include flex(1 200px);
    @include order(2);
    -moz-display: inline-flex;
    display: inline-flex;
    flex-flow: row nowrap;
    justify-content:space-around;
    align-items: stretch;
    list-style-type: none;
    min-width:60%;
    padding: 0;
    margin: 5px 0px 10px 0px;
    border: 1px solid #17100F;
    font-size:.95em;
}

ul.level2listing li.columns {
    margin-left:-40px;
}

ul.level3listing li.columns {
    margin-left:-80px;
}

li.columns div {
    margin:0;
    padding: 2px;
}

li.columns div.col {
    flex: 1 auto;
    border: 1px solid #17100F;
    padding: 0;
    margin:0;
}

li.columns div.col div {
    padding:auto 4px;
}

li.columns div.col div.xxx {
    font-size:.95em;
}

li.columns .header, table.tablelisting th {
    background: #2d201d;
    color:#ffecdd;
    font-weight: bold;
    margin:0;
    padding: 2px 5px;
}

li.columns .header a, table.tablelisting th a {
    color:#ffdddd;
}

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

Utilizing Bootstrap Columns for Image Alignment: Struggling to Position an Image in the Center

For my latest project, I used Bootstrap to create a template that adapts well to different device breakpoints. Everything is working smoothly except for the positioning of the arrows on the sides of the image. I want them to be centered halfway down the ...

When a mobile device is rotated, the screen on a jQuery application will automatically shrink

Having trouble with JQM and device rotation on iOS devices. The screen doesn't resize properly when rotated. I have this line in the header to handle display size: <meta name="viewport" content="height=device-height,width=device-width,initial-scal ...

The Surprising Nature of <div> when containing <a> (anchor tags)

There are 3 div elements on a page. div { display: inline-block; margin: 10px; width: 200px; height: 200px; background-color: #333; color: white; text-align: center; } <div></div> <!--Div ...

Is there a way to implement an onclick event on a specific line of text that triggers a popup box only when the text is clicked, without the popup appearing automatically when

I received assistance from a fellow user to customize a popup that turned out great. However, I'm having trouble getting the onclick function to work properly so that the popup only appears when the phone number is clicked. Ideally, I want the phone n ...

Activate anchor classes in several anchor link menus simultaneously

I have a one-page website with multiple menus filled with anchor links. Here is an example of what they look like: <ul> <li><a href="#home" class="active" onclick="closeNav();">Home</a></li> <li><a href="#abo ...

Disable the outer div scrolling in VueJS, but re-enable it once the inner div has reached the bottom of

I am currently working on a webpage that contains multiple divs stacked vertically. Here is the concept I am working with: Once the scrollbar reaches the bottom of the first div, the outer scrollbar will be disabled and the inner scrollbar will be enabled ...

Tips for positioning two fields side by side on a webpage with CSS

I currently have two datepickers aligned vertically and I'm looking to display them in a horizontal layout with some spacing between them. What changes do I need to make in order to present these two calendar pickers side by side on the same row? Cou ...

I am creating accordion-style bootstrap tables using data generated from an ng-repeat loop, all without the use of ui.bootstrap or jquery

My attempt at creating a table with rows filled using ng-repeat is not working as expected. I want a collapsible panel (accordion) to appear on click of each row, but only a single row is rendering with my current code. Here is a link to my code: var ap ...

How to implement Bootstrap 5 Floating Label in Contact Form 7 for maximum impact?

I'm having trouble with the new form feature, specifically Floating labels (Bootstrap 5) in Contact Form 7 on Wordpress. The issue arises when a <p> tag is added inside the <input> tag. It seems to break the functionality, but I'm not ...

Can HTML code be saved in "context" and then utilized in one of the templates?

I am striving to extract the code of a table from another website using selenium, save it in the context dictionary, and then embed it into one of the templates so that it seamlessly becomes part of the page's HTML structure without displaying the cod ...

Bring to the front the div altered by a CSS3 animation

Recently, I encountered an issue with a div card that triggers an animation when clicked. The animation involves the card scaling up larger, but the problem arises as its edges get hidden under other cards. To visualize this, take a look at the screenshot ...

Input the chosen icon list values into a designated box

As a beginner in the world of Javascript, I am venturing into creating a password generator that involves using icons. The concept is simple - by clicking on any number of icons from a list, the corresponding hex code will be displayed in an input box. The ...

Alert: CSS 4.0 Warning Validation - The value "rgb(0, 0, 0, 0.4)" is not valid for the "border" property

Wrapping up my asp core 3 project, I've been addressing various warnings that have popped up. However, one particular warning has me stumped. The CSS property in question is functioning perfectly, adding a touch of transparency to the black border. Wh ...

Is the append() function malfunctioning in jQuery?

Why is it copying two lines when I only want one line to be cloned on button click? Is there a way to make sure that only a single line is copied each time the button is clicked? Here is my code: $(function() { $('.add-more-room-btn').clic ...

Stunning Opening and Closing Animation with Ajax

Looking for help with creating an animation like the one shown here: Incorporating this into my current site at: dageniusmarketer.com/DigitalWonderland/ I want the window displaying text content to open and close as users navigate through the links, ess ...

Flickering Button Displayed After Fade-In Animation

After scouring the internet for a solution, I still can't seem to figure out why my code isn't working. Whenever an element fades in on Safari, it quickly flickers or flashes white, almost like a rapid refresh is happening. I've tried vario ...

Javascript retrieve the style of an element in every possible state

I am interested in retrieving the line height of an element; it's a simple task. Here is a method that I know works: console.log(document.getElementById("myDiv").style.lineHeight); console.log($("#myDiv").css('lineHeight')) ...

The inefficiency of invoking Jquery on elements that do not exist for the purpose of caching

What is the impact if JQuery attempts to access elements that do not exist? Will there be any significant CPU overhead other than script loading? Does it matter if this is done for a class or an id? For optimization purposes and to minimize simultaneous c ...

Modify CSS progress circle to update the percentage of completion

I stumbled upon this code snippet, and although it works flawlessly, I encountered a limitation - I can only set the percentage to 25, 50, or 75. If I try to increase it to 85%, the circle fills up completely. Does anyone have any suggestions on how to res ...

Is it possible to access forms and input fields in an AngularJS script without having to pass them from the HTML code?

Seeking a solution for input field validation, I have written code where input field states are passed from HTML to a script through a function. However, my goal is to directly retrieve the values in the script without passing them from the HTML when calli ...