When I have a lengthy description, the alignment of the CSS DIV prices becomes misaligned

When I have a long description, the prices appear misaligned. You can take a look at it here: https://i.sstatic.net/aXgaj.jpg

For the JSFiddle example, visit: https://jsfiddle.net/2n19tv75/

.border-gray {
  border: 1px solid #e5e7eb;
  float: left;
  width: 100%;
  min-height: 185px;
  display: inline-block;
  width: 100%;
  height: 100%;
  padding: 20px;
}

.menu-item-name {
  float: left;
  width: 60%;
  font-weight: 600;
  border: 1px solid blue;
}

.menu-item-price {
  width: 100%;
  float: right;
  font-weight: 700;
  text-align: left;
  border: 1px solid red;
}

.menu-item-desc {
  float: left;
  color: #889194;
  width: 60%;
  border: 1px solid green;
  display: inline-block;
  min-height: 80px;
}

.menu-item-image {
  float: right;
}

.menu-sectionname {
  margin-top: 50px;
}

.menu-row {
  --bs-gutter-x: 2rem !important;
  /* control column gap */
  --bs-gutter-y: 2rem !important;
  /* control row gap */
}
<head>
  <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d7b5b8b8a3a4a3a5b6a797e2f9e6f9e4">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous" />
</head>

<body>
  <div class="container">
    <div class="menu">
      <div itemscope="" itemtype="http://schema.org/MenuSection">
        <div class="menu-sectionname">
          <h4>h4</h4>
        </div>
        <div class="menu-section row menu-row">
          <div class="menu-item col-12 col-sm-12 col-lg-6">
            <div class="border-gray">
              <div class="menu-item-name">
                <p>p text</p>
              </div>
              <div class="menu-item-image">
                <img itemprop="image" src="https://i.imgur.com/ZIsnpPF.jpg?auto=format&amp;w=120&amp;h=120" alt="" />
              </div>
              <div class="menu-item-desc">
                <p>working good</p>
              </div>
              <div class="menu-item-price">
                <span itemscope="" itemtype="http://schema.org/offers"><span itemprop="price"><p>€5.00</p></span></span>
              </div>
            </div>
          </div>
        
         [Additional content omitted for brevity]
           
        </div>

      </div>
    </div>
  </div>
</body>

Answer №1

To align items on each row start, simply add the align-items-baseline class.

.border-gray {
  border: 1px solid #e5e7eb;
  float: left;
  width: 100%;
  min-height: 185px;
  display: inline-block;
  width: 100%;
  height: 100%;
  padding: 20px;
}

.menu-item-name {
  float: left;
  width: 60%;
  font-weight: 600;
  border: 1px solid blue;
}

.menu-item-price {
  width: 100%;
  float: right;
  font-weight: 700;
  text-align: left;
  border: 1px solid red;
}

.menu-item-desc {
  float: left;
  color: #889194;
  width: 60%;
  border: 1px solid green;
  display: inline-block;
  min-height: 80px;
}

.menu-item-image {
  float: right;
}

.menu-sectionname {
  margin-top: 50px;
}

.menu-row {
  --bs-gutter-x: 2rem !important;
  /* control column gap */
  --bs-gutter-y: 2rem !important;
  /* control row gap */
}
<html>

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

</head>

<body>
  <div class="container">
    <div class="menu">
      <div itemscope="" itemtype="http://schema.org/MenuSection>
        <div class="menu-sectionname">
          <h4>h4</h4>
        </div>
        <div class="menu-section row align-items-baseline menu-row">
          <div class="menu-item col-12 col-sm-12 col-lg-6">
            <div class="border-gray">
              <div class="menu-item-name">
                <p>p text</p>
              </div>
              <div class="menu-item-image">
                <img itemprop="image" src="https://i.imgur.com/ZIsnpPF.jpg?auto=format&amp;w=120&amp;h=120" alt="" />
              </div>
              <div class="menu-item-desc">>
                <p>working good</p>
              </div>
              <div class="menu-item-price">
                <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="menu-item-name">
                <p>p text</p>
              </div>
              <div class="menu-item-image">
                <img itemprop="image" src="https://i.imgur.com/ZIsnpPF.jpg?auto=format&amp;w=120&amp;h=120" alt="" />
              </div>
              <div class="menu-item-desc">
                <p>working good</p>
              </div>
              <div class="menu-item-price">
                <span itemscope="" itemtype="http://schema.org/offers"><span itemprop="price"><p>€4.50</p></span></span>
              </div>
            </div>
          </div>

Answer №2

To prevent the text from disappearing, one option is to create a text box with a fixed height that is able to accommodate the longest text. However, this may not be the ideal solution for your situation.

If alignment of the price is crucial, you could consider moving it to either the side of the text using flexbox or positioning it above the text. This way, the length of the text won't affect the overall layout.

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

The functionality of Three.js arc drawing in canvas renderer seems to have encountered issues on Chrome

Looking at this example from the library, it is clear that the circles are adjusting their line width and appear thin when they are in close proximity. This functionality used to function properly. Currently, I am using Chrome version 27.0.1453.93 on OSX ...

Using JQuery to toggle image visibility, starting with the first image and scrolling through until only one image remains visible

I am facing a challenge where I am unable to modify the HTML code. The current structure is as follows: <div class="slider"> <div class="slider-control"> <button id="prev">Previous</button> ...

AngularJS : Resolving Alignment Issues with ng-repeat and ng-include

The ng-repeat feature is being utilized here with an inclusion of a different HTML partial. <div ng-repeat="item in feedItems"> <div ng-include="'item.itemType.html'"> </div> </div> Below is the CSS for the partial H ...

Align watermark content to the far left side

Having trouble getting my watermark to align properly on the left side of my website's main content. Here is how it currently looks: https://i.sstatic.net/Nfhh5.png The issue arises when I resize the screen or switch to mobile view, as the watermark ...

Issue with Bootstrap 5: Content alignment in Card headers not floating correctly to left and right

I've been working on a Bootstrap 5 card that has a title on the left and a group of buttons on the right in the header. Here's my code: <div class="card-header"> <div class="float-start"> <h3>title</ ...

Switch between different content sections using a button in a Bootstrap tab-pane

Here is the code snippet I am currently working with: <!DOCTYPE html> <html lang="en"> <head> <title>Bootstrap Example</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-s ...

Trigger Ajax POST on modal close button click

I am facing an issue with my modal where it still performs an Ajax post even after clicking the 'Close' button. I want to prevent the Ajax post when the user clicks on 'Close'. Any suggestions on how to handle this situation? Modal &l ...

How to Align Image in the Middle using Bootstrap 4

After attempting to use mx-auto to center an image within a Bootstrap 4 card just beneath the card-text, I found that the image remained left-justified. <img src="my.svg" class="mx-auto" alt="..."> I also tried placing the img inside a div and usin ...

dividing JavaScript files in the three.js game development platform

After spending two years teaching myself unity/c#, I believe I have the coding skills to transition from an engine to a framework for better control over the environment. As I started working on first person environment features, I wanted to organize my co ...

What is the method for printing a webpage that has been modified using JavaScript?

Take a look at this screenshot to see what I'm working with. Users have the ability to modify the page by removing items, adding new items, or marking items as complete by crossing them out. I want users to be able to print the altered page using Jav ...

Ways to grab attention as a visitor leaves a website

My company specializes in creating web surveys. Occasionally, we are asked if it is possible to conduct an exit survey on a website. This would involve displaying a "popup" to visitors as they are about to leave the site, prompting them to take a quick sur ...

Incorporating dynamic dictionary fields in Reactive and pushing them into an established FormControl

I am attempting to dynamically populate my reactive form with varying fields based on user selection. Here is an example of the fields I have: fields = [{ df_id: 48, df_name: "Phone Number", df_type: "text", ...

I would like my division to split into two halves, each with a width of 50%, and be aligned next to each other using fxLayout

<div fxLayout="row" fxLayoutAlign="space-between" style="background-color: blue;"> <div fxLayout="column" style="width: 50%;">1stOne </div> <div fxLayout="column" styl ...

Is it advisable to incorporate multiple images onto a single canvas?

What is the best approach to handling multiple images in HTML5? Is it preferable to create a separate canvas tag for each image or is it equally effective to have multiple images in one canvas, and how would I go about doing that? Here is the code I have ...

Assigning a unique identifier to a button that will vary depending on the selected radio input

UPDATED HTML: The circumstances have changed because I am no longer in my office, but the concept remains unchanged. The situation is that on a certain part of a website, users have the option to choose from multiple saved addresses. Each address has a un ...

Is there a way to show text as symbols in Primeng components?

Check out this helpful example that demonstrates what I am attempting to achieve. I have implemented p-menu from primeng. Is there a method to convert text into symbols like &trade to ™ and &#8482 to ®? ...

Is it possible to customize the placement of the login or register success message?

I would like to display a message indicating whether the login/register process was successful or not above my form. I am using Boostrap 3 along with some PHP functions. The message appears above my navbar but vanishes after 3 seconds, which is a bit anno ...

Is it possible to hide the <dd> elements within a <dl> using knockout's custom data binding upon initialization?

I have implemented a <dl> where the <dd> can be expanded/collapsed by clicking on the corresponding <dt> using knockout's data binding. The inspiration for my solution came from a tutorial on creating custom bindings. Currently, I h ...

Modify the dropdown menu title dynamically based on the selection made in Angular

My Angular web-application has a dropdown menu that looks like this: <div class="btn-group" dropdown> <button dropdownToggle type="button" class="btn btn-primary dropdown-toggle">NAMEOFDROPDOWN <span class="caret"></span>&l ...

Enhance your React/Bootstrap project with a hover effect class similar to Tailwind CSS's :hover feature

Is there a way to achieve the hover effect in React using Bootstrap similar to Tailwind's approach? I've searched online but haven't found any solutions. Appreciate any help! ...