I'm experiencing some unwanted white spaces between my div elements, likely caused by varying heights. Is there a way to remove these spaces without having to resort to setting a fixed

I came across a similar thread discussing my issue, where the suggested solution was to set a fixed height. However, this approach is causing some problems with the responsiveness of the theme I am using. Let me provide more details.

The theme I am working with is from Prestashop and can be viewed here. The demo images in this theme are taller at 395 x 468px compared to my product images which are around 355 x 240px. Due to this difference in heights, random empty spaces are appearing between the images. To address this issue, I made some adjustments which have resulted in the following layout:

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

To temporarily fix this problem, I enforced a height of 400px on the

<div class="product-container">
within
<li class="ajax_block_product>
:

ul.product_list.grid > li .product-container {
    position: relative;
    height: 400px;
}

Unfortunately, this solution has impacted the overall responsiveness of the theme. In various screen views such as tablets, mobile devices, or other screens, the fixed height of 400px either falls short or results in excessive spacing between divs vertically. As a temporary workaround, I implemented different heights (300px, 380px, 420px) using @media rules for product-container. However, I acknowledge that this method is not ideal and there may be a better alternative that I am overlooking. I would greatly appreciate any suggestions or solutions you may have!

Answer №1

To achieve a responsive layout, consider utilizing flexbox with wrapping applied to the container like this:

ul.product_list.grid {
  display: flex;
  flex-wrap: wrap;
}

Answer №2

To resolve this issue without imposing a fixed height on the product-container, all images must be adjusted to have identical heights. In response to @JiFus, I noted:

After removing the forced height on product-container and inspecting the elements, I discovered that some containers had a height difference of just 1px compared to the others.

Prestashop offers an option to regenerate images with specific dimensions, so I will experiment with the settings in the hopes of achieving the desired outcome.

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

Ensure that a child div is displayed above the parent div that is absolutely positioned

Is it possible to have a child div within an absolutely positioned parent div appear above its parent, aligned in such a way that the top of the child div aligns with the bottom of the parent div, while also being displayed above neighboring parent divs on ...

How to reference global Sass variables in a Sass module

My preferred method involves utilizing a global .scss file that houses all the foundational styles, such as primary color selections. Following this, I create separate modules for each React Component to maintain organization and reduce the need for import ...

Maintain text while transitioning to another page

On my webpage (refer to image for details), users need to select options through a series of steps. The process involves clicking on a link in the top box, then entering a search term in the searchbox to display relevant links in div1. Clicking on a link ...

Error encountered in onclick handler due to unterminated string literal in PHP and jQuery

Trying to utilize PHP to send variables into the onclick of an element is resulting in an "Unterminated string literal" error due to long strings. Below is a snippet of my PHP code: $query = $conn->prepare("SELECT Name, Image, Description, Link, Price, ...

How can I create a thumbnail rectangle and wrap item text with Ionic framework?

Just diving into Ionic and I have a quick query that's not covered in the documentation. Is there a straightforward way to utilize Ionic classes to left-align content currently positioned below an image? The code snippet I'm working with looks ...

Stop material button from animating when clicked

On my webpage, I have created a unique button structure using Angular Material design: <button mat-button class="library-tile-button"> <button mat-button class="edit-library-button"> <img class="edit-library-img" src="..."/> ...

What steps can I take to ensure my menu is responsive in the right way

What is the best way to create a responsive menu that displays properly on cell phones? On computers, it looks like this: [insert image description here][2] I'm having trouble with my menu not disappearing when I select an option, instead it just goe ...

Adjust the dimensions of the MaterialUI Switch component manually

Struggling to resize a Material-UI Switch as the default size isn't suitable. Managed to increase the size, but now the behavior isn't ideal. It looks fine in its default state: https://i.sstatic.net/qLpDZ.png. However, when changing its sta ...

The hover action in the Jquery Accordion does not activate when a section has been opened before

I'm facing a problem with my jQuery accordion menu. After opening and closing a section, the ':hover' effect stops working only for that specific section. However, it continues to work for other sections that haven't been clicked yet. ...

Replacing HTML text with JSON data can be easily achieved by using JavaScript

After receiving data from an API and converting it into JSON format, I encountered difficulty when attempting to change a selected element in HTML. Every time I tried to do so, I either got 'undefined' or 'Object Object' as the output. ...

Implementing a Javascript solution to eliminate the # from a URL for seamless operation without #

I am currently using the pagepiling jQuery plugin for sliding pages with anchors and it is functioning perfectly. However, I would like to have it run without displaying the '#' in the URL when clicking on a link like this: www.mysite.com/#aboutm ...

Display a preview of the image when hovering over a dynamically generated dropdown menu

I have come across numerous posts where hovering over an item in the dropdown bar reveals an image. However, all of these posts have hardcoded the items in the dropdown within the HTML. I am dynamically generating the dropdown items using JavaScript and I ...

radio option block

I would like to create a block for radio buttons. Here is the code I have: <label> Rating <input type="radio">great <input type="radio">wonderful </label> Unfortunately, it is not functioning as expected. ...

The matter at hand pertains to the aesthetics of formatting HTML components

Below is my attempt at creating a search box and styling it. However, I am encountering an issue where the CSS properties applied to the box are not being rendered. I have tried including the CSS in a separate file as well as within the script itself, but ...

Mapping JSON data containing a collection of objects as an observable, rather than as an observable array, is an

When developing my webpage, I needed to receive a viewmodel of a user account via Json. The data includes essential user details such as real name and email address. Additionally, I wanted to display (and modify) the groups that the user belongs to, along ...

What is the reason behind the _set.all function not working in the template?

I have a scenario where I have three interconnected models: GroupRequirementType --> GroupRequirement --> Requirement. When trying to display all requirements in the template, only GroupRequirementType objects are being shown. It appears that there m ...

Struggling to incorporate a logo into the navigation bar for an HTML project

I'm a beginner in the world of HTML and CSS, trying my hand at creating a homepage. While I managed to add a logo to the Navigation bar, it seems to have messed up the link for the HOME page. Could this be due to not wrapping the logo in a div or imp ...

Aligning MaterialUI Grid items vertically within various Grid containers

Looking to implement a design that features three vertical columns. The first and last columns will display MaterialUI cards, while the middle column will showcase a vertical line with dots aligned vertically with the start of each card. The height of the ...

Tips on choosing a text option from a selection menu

When I try to retrieve the text displayed in my select menu upon selection, I encounter a challenge. While this.value allows me to fetch the value, both this.label and this.text return as undefined. Is there a method to extract the visible text from the d ...

Troubleshooting the Angular 7 mat-select issue caused by the "ellipsis" CSS property with three dots

I am facing an issue with a mat-select property called "ellipsis". The three points appear in a different color than the text itself. I attempted to change it to white using the following code, but the dots still remain black. ::ngdeep .example{ ...