Flex and Bootstrap 5.1.3 divs are not aligned with the prices

I have implemented flex from here

Whenever the content text increases in size, the div and the price do not remain aligned. See image here.

My goal is to achieve the following:

  • Make sure the div maintains the same size whether the content text is long or short.
  • Ensure that the price always stays aligned with the content even when it expands.

Link to JSFiddle: Here

<html>

<head>
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="20424f4f54535452415060150e110e13">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous" />
</head>
<style>
.border-gray {
    border: 1px solid #000;
    min-height: 100px;
    padding: 20px;
}
</style>


<body>
<div class="container">
    <div>
        <h4>section name</h4>
    </div>
    <!-- <div class="menu-section row align-items-baseline menu-row"> -->
    <div class="menu-section row align-items-baseline">
        <div class="menu-item col-12 col-sm-12 col-lg-6">
            <div class="border-gray">
                <div class="d-flex justify-content-between bd-highlight mb-2">
                    <div class="p-2 bd-highlight">
                        title
                        <div>
                            t contentcontent contentcontent contentcontent contentcontent content content contentcontent contentcontent content
                        </div>
                    </div>

                    <div class="p-2 bd-highlight">
                        <img itemprop="image" src="https://i.imgur.com/ZIsnpPF.jpg?auto=format&amp;w=120&amp;h=120" alt="" />
                    </div>
                </div>

                <div class="d-flex align-content-end flex-wrap">
                    <span itemscope="" itemtype="http://schema.org/offers"><span itemprop="price"><p>€5.00</p></span></span>
                </div>
            </div>
        </div>
        <div class="menu-item col-12 col-sm-12 col-lg-6">
            <div class="border-gray">
                <div class="d-flex justify-content-between bd-highlight mb-2">
                    <div class="p-2 bd-highlight">
                        title
                        <div>
                            content t contentcontent contentcontent content t contentcontent contentcontentcontent t contentcontent contentcontent content t contentcontent contentcontent content t contentcontent contentcontent content t contentcontent contentcontent content t contentcontent
                            contentcontent
                        </div>
                    </div>

                    <div class="p-2 bd-highlight">
                        <img itemprop="image" src="https://i.imgur.com/ZIsnpPF.jpg?auto=format&amp;w=120&amp;h=120" alt="" />
                    </div>
                </div>

                <div class="d-flex align-content-end flex-wrap">
                    <span itemscope="" itemtype="http://schema.org/offers"><span itemprop="price"><p>€5.00</p></span></span>
                </div>
            </div>
        </div>
    </div>
</div>
</body>

Answer №1

To tackle this issue, the first step is to analyze the two divs in question and identify the one causing alignment problems due to its content length. Once identified, set a minimum height (min-height) on the smaller div based on the rendered size of the larger one.

In your case, the right div appears larger due to more content, resulting in height discrepancies with the left div. By establishing min-height values for both divs, you ensure that each fills the available space and aligns properly. This may also involve setting a maximum height (max-height) on the div with excess content, especially during browser resizing and content wrapping scenarios.

This approach should accommodate variable content sizes provided you adhere to the outlined methodology, focusing on determining the optimal min-height. Refer to the sample CSS snippet below showcasing the min-height configuration for border-gray along with inline styles defined for its initial child elements:

.border-gray {
  border: 1px solid #000;
  padding: 20px;
  min-height: 300px;
}
<html>

<head>
  <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="27454848535453554657671209160914">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous" />
</head>

<body>
  <div class="container">
    <div>
      <h4>section name</h4>
    </div>
    <div class="menu-section row align-items-baseline menu-row">
      <!-- <div class="menu-section row align-items-baseline"> -->
      <div class="menu-item col-12 col-sm-12 col-lg-6">
        <div......(truncated).......       

Answer №2

Have you attempted adjusting the height of one element and setting the other to height:auto? Additionally, it is advisable to simplify the code to make troubleshooting easier.

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

Ensuring a logo remains centered and stable even when the browser is resized

How can I ensure that this logo remains fixed at the center top of the page, without moving as the browser size changes? I want the logo to maintain its position and not recenter itself when the browser is resized. Below is my current CSS CSS #logo { p ...

How can I properly integrate jQuery libraries, along with CSS, in a create-react-app project?

I'm currently working on incorporating the select2 jquery library into my React application, which was created using create-react-app. After adding jquery and select2 to my package.json file, I was able to get the javascript functionality to work pro ...

Close button in Popover not functioning properly for SVG element

Concern I am facing an issue with a popover close button in this fiddle. The close button on the popover seems to work only once. Detailed Explanation My goal is to create SVG elements dynamically through Angular directives, and I want them to have Popo ...

What could be causing my buttons to malfunction once I've applied padding to the container?

I'm struggling with getting my buttons to appear active. They currently don't have any functionality and lack a hover effect when clicked. Despite my efforts to add effects, nothing seems to change. After experimenting with the CSS, I've no ...

Determining the file size of an HTML and JavaScript webpage using JavaScript

Is there a way to determine the amount of bytes downloaded by the browser on an HTML+JS+CSS page with a set size during page load? I am looking for this information in order to display a meaningful progress bar to the user, where the progress advances bas ...

Ways to avoid unintentional removal of contenteditable unordered lists in Internet Explorer 10

How can I create a contenteditable ul element on a webpage while avoiding the issue in Internet Explorer 10 where selecting all and deleting removes the ul element from the page? Is there a way to prevent this or detect when it happens in order to insert ...

HTML Remover resulting in a malfunction

Currently in the process of removing HTML tags from text using the following method: <p><b>Masala</b> films of <a href="/wiki/Cinema_of_India" title="Cinema of India">Indian cinema</a> are those that combine different genres ...

Guide on how to modify the CSS styling of a particular <td> element when its parent contains a specific class

.webgrid-table td, th { border: 1px solid #98bf21; padding: 3px 7px 2px; } I am facing an issue where the style defined above is being applied to all td elements. However, I want to exclude the styling for a td that is within a tr element with the ...

Troubleshooting Bootstrap: Issues persist even after including CDN links and reference style link // Python

Currently, I'm in the process of constructing my Django app. After successfully implementing the login page and homepage, I decided to give my page a much-needed facelift since it looked extremely basic. A big fan of Bootstrap, I've used it exten ...

What is the procedure for automatically playing the next audio track in HTML5 after the current one finishes playing

When trying to play a single MP3 file, the code below is designed to skip to a specific part of the track and then start playing from that position. However, despite the cursor moving to the correct spot in the MP3, it fails to play upon clicking the Sta ...

Displaying MySQL results in a vertical sequence

I've stored the data in my database as follows: Football ART-NR-1337 Price: 5$ Basketball ART-NR-1333 Price: 10$ Now, I am working on a .php file that displays the articles like this: Football Basketball ART-NR-1337 ART-NR-1333 Price: 5$ ...

When placed within a <li> element, the <a> tag will not create a hyperlink to a page, but it will

I have encountered an issue with my anchor links. All of them are working properly except for the one in the second ul with an href="page1". Interestingly, the link shows the correct destination at the bottom left of my screen and works when I right-click ...

When you click on the input field, a file manager window will open. You can then select a file and the URL of the selected file will be automatically added to the

I need assistance with customizing the code to open the flmngr window and add the URL of the selected file to the input field when onclick. window.onFlmngrAndImgPenLoaded = function() { var elBtn = document.getElementById("btn"); // Style bu ...

Enhancing Form Attributes in Django Crispy Forms

When using bootstrap switch, adding a label requires the following syntax: <input name="switch-labelText" type="checkbox" data-label-text="Label"> With crispy forms, attributes can be added to fields using Field like th ...

How can I apply bold styling to my interpolation binding in Angular while working on my HTML code?

Below is the code snippet where I am attempting to highlight profile.userId: <p class="profile__last-login" *ngIf="profile.lastLoggedIn"> {{'intranet.profile.dashboard.lastLoggedIn' | messageBundle: profile.userId + ',' + (pr ...

Ways to verify if one div in jQuery contains identical text to another div

I need help with a jQuery script to remove duplicate text in div elements Here's the requirement: If div1 contains the text "hi" and div2 also contains "hi", then div2 should be removed Below is my current code snippet: <script src="https:/ ...

Iterating through an array with ngFor to display each item based on its index

I'm working with an ngFor loop that iterates through a list of objects known as configs and displays data for each object. In addition to the configs list, I have an array in my TypeScript file that I want to include in the display. This array always ...

Discovering unmarked content using Jsoup

I have been struggling to find a solution to my problem, but so far I have not found any clear answers in my search results. I have spent a considerable amount of time trying different suggestions from various posts that seemed somewhat related. Now, let&a ...

Utilizing conditional statements like if/else and for loops within a switch statement in JavaScript allows for

I am currently developing a request portal that involves dynamic checkboxes, labels, and textboxes that are dependent on an option list. As a beginner in javascript, I am facing challenges with creating conditional statements. I have managed to make progr ...

Bootstrap 4 alert boxes extend the text to span the entire width of the alert

How can I make the paragraph text span across most of the box width in Bootstrap 4? <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJ ...