Issue with the alignment of two rows in an HTML template

I'm encountering an issue with the spacing between two rows/elements in an HTML template. I'm working on creating a product grid for our restaurant and used a template sourced from the Internet. As shown in this picture: issue1

The problem lies in the spacing between the first line and second line elements when adding a new row of text. Whenever I add a new row using the p element, the entire 2nd row seems to drop down significantly, causing unwanted space.

Here is the HTML code I'm using (issue version vs. non-issue version)

<div class="col-12 col-sm-6 col-lg-4">
    <div class="single-best-receipe-area mb-30">
        <img src="https://www.coopathome.ch/img/produkte/880_880/RGB/4798850_001.jpg?_=1527527264626" width=290px height=304px alt="" class="center-block" />
        <div class="receipe-content">
            <h5 style="line-height: 0px;">Barilla - Penne Rigate fără gluten 400g</h5> <p style="color:#ff9400; text-decoration: line-through;" >14,00 RON</p> <p style="color:#ff9400; line-height: 0px;"> REDUCERE 10% - 12,00 RON</p>
        </div>
    </div>
</div>

<!-- Single Best Receipe Area -->
<div class="col-12 col-sm-6 col-lg-4">
    <div class="single-best-receipe-area mb-30" >
        <img src="https://www.coopathome.ch/img/produkte/880_880/RGB/4798854_001.jpg?_=1505902808944" width=320px height=304px alt="" class="center-block" />
        <div class="receipe-content">
            <a href="receipe-post.html">
                <h5>Barilla - Spaghetti fără gluten 400g</h5>
            </a>
        </div>
    </div>
</div>

Below is the custom CSS that has been added:

.single-best-receipe-area .receipe-content {
padding-top: 30px;
text-align: center;
}
.mb-30 {
vertical-align: middle;
margin: 0 auto;
}
.receipe-content {
line-height: 0px;
}

Despite trying the suggestions from StackOverflow, such as using line-height: 0px, I haven't had any success. Unfortunately, I am not a web developer and simply attempting to create a menu list for our restaurant. Any help would be greatly appreciated. Thank you!

EDIT: Demo with code:

EDIT2: A more detailed image of the issue can be found here: issue2

Answer №1

To enhance the provided code, modify the HTML to include a 'flex-height' class to the first div with the current class of 'row':

<div class="row flex-height">
    <div class="col-12 col-sm-6 col-lg-4">
                    <div class="single-best-receipe-area mb-30">
                        <img src="https://www.coopathome.ch/img/produkte/880_880/RGB/4798850_001.jpg?_=1527527264626" width=290px height=304px alt="" class="center-block" />
                        <div class="receipe-content">
                                <h5>Barilla - Penne Rigate fără gluten 400g</h5> <p style="color:#ff9400; text-decoration: line-through;" >14,00 RON</p> <p style="color:#ff9400;"> REDUCERE 10% - 12,00 RON</p>
                        </div>
                    </div>
                </div>

                <!-- Single Best Receipe Area -->
                <div class="col-12 col-sm-6 col-lg-4">
                    <div class="single-best-receipe-area mb-30" >
                        <img src="https://www.coopathome.ch/img/produkte/880_880/RGB/4798854_001.jpg?_=1505902808944" width=320px height=304px alt="" class="center-block" />
                        <div class="receipe-content">
                            <a href="receipe-post.html">
                                <h5>Barilla - Spaghetti fără gluten 400g</h5>
                            </a>
                        </div>
                    </div>
                </div>
</div>

Below is the updated CSS:

.single-best-receipe-area{
  text-align:center;
  line-height:30px;
  padding-top:20px;
}
.receipe-content{
  padding-top:30px;
}
.row.flex-height {
  display: flex;
  flex-wrap: wrap;
}
.row.flex-height > [class*='col-'] {
  display: flex;
  flex-direction: column;
}

This modification results in a more visually appealing layout. Check out the JSFiddle example here (resize your browser to see how it adapts to different screen sizes) - New JSFiddle

I hope this explanation proves helpful.

Answer №2

Styling for card images:

.card-img{ display: flex; flex-wrap: wrap; }

Answer №3

<style>
  .recipe-content-section .content {
    margin-top: 50px;
    text-align: center;
    display: flex;
    flex-direction: column;
  }
</style>

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

ASP Table extends into adjacent column

Having some trouble with the table layout here. In the screenshot, you'll notice a grid view within another gridview. There are currently 3 grid views - the main one and one in each table. I'm looking to move the description to the Price 2 column ...

Touching a link within an absolute DIV in CSS on mobile devices is not responsive

When I try to click on links inside a div with the position:absolute style, they don't seem to work on my Android mobile device. However, they work perfectly on both Chrome and even IE8 on my desktop. Removing the style makes the links functional. Th ...

Changing icons using JQuery when clicking 'show more' or 'show less' buttons

I am currently utilizing https://github.com/jasonujmaalvis/show-more to display and hide text content on a mobile device. My goal is to switch between images for show more and show less: Here's what I have so far: Jquery: Source File: ; (function ...

Tips for handling null input values when saving to a database

<!DOCTYPE html> <html> <head> <title>Data</title> </head> <body> /* Enter your data here */ <form action="this.php" method="post"> <input type='text&a ...

CSS :empty selector failing to target elements

I have a situation where I utilized the :empty selector within the .error class. However, I'm encountering an issue where even if there is no content inside the div with the error class, the error class does not get removed entirely. Upon examination ...

The functionality of reordering columns, virtual scrolling, and resizing the grid in jqgrid are not functioning properly

Implementing jqgrid with Symfony to display a datagrid has been a challenging task for me. Thanks to Oleg's insightful response, many of the major issues have been resolved. Below is a snippet of my code: <link rel="stylesheet" type="text/css" ...

What is the method for locating all anchor tags "In General" within the inner HTML of a div using XPath?

This query is related to a discussion on anchor tags in this thread. I am interested in identifying all anchor tags within a string. The scenario provided below is similar to the aforementioned issue, however, I aim to accomplish this using xpath and angu ...

Two resizable divs positioned next to each other - first div adapts to the size of the second div

I have a unique challenge with two divs positioned side by side. The first div contains random text of varying lengths, while the second div holds a random number of inner divs. My goal is to have these two divs completely fill the space within their wrap ...

Tips for showing a table during onfocus event?

I have created an input text field with a label for a name. When I enter a name in the text box, it displays some related names using the onfocus event. Now, my goal is to display a table under the text box with the ID or NO and NAME when a name is entered ...

Two flex boxes displayed next to each other on the screen

Within the .maroon section, there are two .whitewrap sections. I am puzzled as to why they are not wrapping onto another line and instead displaying side by side. The form should be positioned below the text and graphic with some maroon showing in between. ...

JavaScript can be used to manipulate buttons and interact with them on a webpage

In my search for examples for my webpage, I stumbled upon a strange JQuery selector. Could someone please explain how this works and if I can use it to target unique indexed IDs in HTML? //The mysterious selector that puzzles me //What does "^" actually ...

Exploring the world of HTML and Javascript to enhance user search functionality

When I type in the search form, JavaScript is returning an error: "Uncaught TypeError: Cannot read property 'innerText' of null". I am working on a page with Bootstrap cards and trying to filter them by name. I attempted to access the "card-titl ...

Guide to adjusting the screen resolution on your iPad 3

Hello everyone, I'm fairly new to designing for the iPad 3. Could someone please provide some guidance on how to set media queries specifically for the iPad 3? Thank you in advance. ...

The requested style from ' was denied due to its MIME type ('text/html') not being compatible with supported stylesheet MIME types, and strict MIME checking is enforced

It's strange because my style.css file in the public folder works on one page but gives me an error on another. I'm not sure why it would work on one page and not on the other. The CSS is imported in index.html so it should work on all pages of t ...

Encountering a parsing error when utilizing the fill CSS property in React

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"> <g id="flat"> <path d="M43,43H38.952a2.3,2.3,0,0,1-2.273-1.926h0a4.816,4.816,0,0,0-3.642-3.962,4.728,4.728,0,0,0-5.695,3. ...

Center the text within the div and have it expand outwards from the middle if there is an abundance of text

I have a div that is in the shape of a square box and I want it to be centered. No matter how much text is inside, I would like it to remain in the middle. I am using JQuery to create my square box and would like to center it using CSS. Here is my code: &l ...

Tips on how to showcase a picture with the focus on the center by enlarging it within

We have a long frame on the page, with an aspect ratio of about 3.5:1 width to height. However, most of the photos being displayed are in a 4:3 ratio, which is larger and not a proper fit for the frame. The customer really wants the long frame and has no ...

Using JQuery to properly introduce a script in the body of a webpage

<script> /* adjust #splash-bg height based on #meat element */ $(window).on('load',function(){ var splashbgHeight = $("#meat").css("top"); $("#splash-bg").css("height",splashbgHeight); $(w ...

What is a method for capturing the value of a nested input element without requiring its ID to be

Currently, I am facing a challenge in selecting the value of an input box from a user-generated ordered list of text boxes and logging its value to the console. It seems like I cannot find a way to select the value of a child's child element when the ...

This method or property is not supported by the object - How to call an Applet in Internet Explorer 9

cmd > java -version Java Version : "1.7.0_11" (Updated) Java(TM) SE Runtime Environment (build 1.7.0_11-b21) Java HotSpot(TM) Client VM (build 23.6-b04, mixed mode, sharing) browsers = IE7,IE8,IE9 (The functionality works smoothly in Google Chrome and ...