What is the best way to ensure that all Grid thumbnails have the same height?

I have a collection of image thumbnails organized in a grid format. The HTML structure uses <ul> as a wrapper and <li> elements to display each thumbnail. I have applied the following CSS properties to the <li> tag:

float: none;
display: inline-block !important; 

The thumbnails are currently displaying in a grid layout, with 3 thumbnails per row instead of the intended 4. The issue arises from using display: inline-block on the <li> elements, which causes a line break after each one. Can you suggest a solution to achieve 4 columns per row while maintaining display: inline-block?

If I switch to float: left for the <li> elements, I would need to set a fixed height for each one. However, the images inside these elements have varying heights.

The challenges include:

  1. To display 4 columns per row instead of 3
  2. To extend the right border to cover the full height of the row, despite different thumbnail heights

Assistance is greatly appreciated.

body {
            background-color: #ddd;
            }

            .list-unstyled {
            background-color: #eee;
            width: 100%;
            }

            .list-unstyled li{
            background-color: #eee;
            float: none;
            display: inline-block !important;  
            padding: 10px;
            margin: 0;
            border-right: 2px solid #ddd;
            border-bottom: 2px solid #ddd;
            box-sizing: border-box;    
            }

            .list-unstyled li img{
            width: 100%;
            }

Answer №1

To achieve your desired result, simply delete the

display: inline-block !important;
property from .list-unstyled li and add display: flex; flex-wrap: wrap; to .list-unstyled.

.list-unstyled {
   background-color: #eee;
   width: 100%;
   display: flex;
   flex-wrap: wrap;
}

View Working Fiddle

Edit:

Add

display: flex; align-items: flex-end;
to .list-unstyled li

See Updated Fiddle

Answer №2

Consider removing the float: none; property from within the .list-unstyled li selector.

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

Enhance your website with Bootstrap 4 by separating text and images in your carousel

I've been struggling to create a slider similar to the one shown in the image. I attempted using the Bootstrap carousel, but ran into issues with inconsistent image sizes and the text on the left side jumping around before settling in its correct posi ...

Softly Transitioning Slideshow with Slide Effects

Has anyone had any experience with FlexSlider or jQuery in general? I've been using the FlexSlider slideshow script and I've made some customizations to fit my needs. You can check it out here: My main query is, does anyone know how to make the ...

How can I apply jQuery styling to ajax content that has been loaded?

After setting up most of the content properly, I am now facing a challenge in styling a select dropdown using the following script: The styling code is as follows: $(function () { $("#select").selectbox(); }); I am wondering how to apply the following c ...

Discovering a specific value within a JSON stringified array

I am looking for a specific value within a JSON stringify array [{"id":"432","temperature":"1","humidity":"1","createat":"0000-00-00 00:00:00"},{"id":"433","temperature":"22.00","humidity":"48","createat":"2015-10-11 19:49:57"},{"id":"434","temperature":" ...

The stylesheet reference, <link rel="stylesheet" href="../css/style.css">, appears to be malfunctioning

My project structure includes css files in a folder named css and jsp files in a folder named jsp, both located inside the WEB-INF folder. I am wondering how to access the css file within a jsp file. <link rel="stylesheet" href="../css/style.css> T ...

Creating a delete functionality button in JavaScript is essential for removing elements from a webpage with ease. This button allows users to seamlessly

I am currently working on an HTML form and here is the code for it: <div id="format"> <form id="myForm" onsubmit="myForm(event)"> <b>Name:</b></br> <input type="text" name="name" id="name" r ...

react-router-redux is unable to navigate to a different URL

I'm working on redirecting within a redux action when an error occurs. I attempted to utilize react-router-redux but encountered the following error. Uncaught TypeError: Cannot read property 'push' of undefined at middleware.js:29 a ...

Retrieve HTML content from a JSON object and render it on a web page

I am facing a challenge with decoding html that is in json format. I'm struggling to figure out how to retrieve my html and display it on a page. It seems like json_decode isn't the solution. Can anyone help me with this issue? Appreciate any as ...

An interactive top navigation bar paired with three dynamic columns housing scrollable content, all crafted seamlessly with Bootstrap 4

I recently updated my layout using bootstrap but I am facing a glitch. I want the layout to have fixed scrolling only within the columns, without affecting the entire page. Everything works fine until I add some text inside any of the columns, then the who ...

Using jQuery to retrieve the HTML code for links

I am looking for a way to extract HTML links from a specific div without relying on regular expressions. Here is an example scenario: <div>Please review the links provided in the content. For instance, <a href="http://en.wikipedia.org/wiki/Apple ...

Minimize a pop-up window and navigate to a different webpage

I have created a login/logout form that includes the option to delete my account. When I click the "Sterge cont" button, a pop-up window appears asking if I truly want to delete the account. If I select "NU," the account will not be deleted and the window ...

Tips for optimizing text retrieval in headless mode with Selenium to avoid unnecessary duplicate runs

My current task involves scraping specific parts of the materials listed on the Zara website. The process I am following includes the following steps: step#1 - opening the website in headless mode step#2 - clicking the "see more" button to reveal the p ...

Displaying HTML content in UITableViewCell on iOS

Can anyone assist me with rendering HTML content containing images and text in different cells of a UITableView? My data source consists of HTML content that needs to be displayed on UITableViewCells. I have attempted using Attributed strings on UILabel a ...

Accessing elements in AngularJS through ng-click function

According to information provided in this answer, it is necessary to pass the $event object to the ng-click function in order to access the target element. $scope.setMaster = function(obj, $event){ console.log($event.target); } Although using event.t ...

Populate several input boxes with data derived from a single input field

I am facing an issue with three textboxes in my project. When I type something in the first textbox, the value is sent to state.jsp and displayed using out.println(firsttextboxvalue); on the response ID of the second textbox. However, I want to populate th ...

What is the process for modifying the characteristics of an RMWC Component?

How can I dynamically change the icon attribute in my RMWC Button element when an onClick event occurs? <Button outlined icon={<CircularProgress />} onClick={(e)=> { // e.currentTarget.icon = ''; // console.log(e.c ...

The 'classProperties' React component module is currently not enabled

Encountering an error while running my react module 'classProperties' isn't currently enabled (44:11): } 43 | // componentDidUpdate or try this > 44 | onClick = (e) => { | ^ 45 | e.preventDefault(); 4 ...

Is the CSS after-before property not functioning properly?

In my CSS code, I am utilizing the after and before tags. This is the structure of my div. However, I am facing an issue where my after tag is not functioning as expected. While everything else seems to be working fine, the after and before tags are not di ...

Python for HTML to PDF Conversion

I have been struggling to convert HTML into a PDF document using Django without any success. Initially, I attempted to utilize wkhtmltopdf 0.9.9, but Apache returned an error stating that wkhtmltopdf could not connect to the server. Surprisingly, when I u ...

Troubleshooting: Issue with jQuery not retrieving the value of input:nth-child(n)

My goal is to dynamically change the price when the model number changes, requiring the id number and quantity to calculate it accurately. Here is the HTML code I have: <div class="col-sm-9 topnav"> <span> ...