Creating identical height columns with uniform inner elements is a problem that needs to be solved with caution. The proposed solution

Issue: I need to create a responsive layout with 5 columns, each containing an image, title, and text. The goal is to align the images separately, titles together, and texts individually while ensuring that all elements in a row have the same height.

Solution implemented: I was able to accomplish this by iterating through the elements I wanted to equalize in height, determining the maximum height, and setting all elements to that height using JavaScript. Additionally, I included a script to repeat this process whenever the window is resized. You can view a demo of my solution on CodePen.

Seeking advice: I am looking for a best practice approach to achieve this outcome. I believe there should be a way to do this purely with CSS.

Thank you everyone!

Answer №1

If you are looking for a way to create cards with equal width and height, consider using Bootstrap's built-in card decks. Instead of relying on rows and columns, give card decks a try:

<div class="container mt-5">
    <div class="card-deck">
        <div class="card">
            <img class="card-img-top" />
            <div class="card-body">
                <h1 class="card-title text-center" />
                <p class="card-text" />
            </div>
        </div>
        <div class="card" />
        <div class="card" />
        <div class="card" />
        <div class="card" />
    </div>
</div>

By wrapping your content in .card, the images should align automatically.


To handle overflow in titles, one strategy is to display "..." when they exceed a single line. This ensures aligned titles that occupy only a single line. Bootstrap provides a class for truncating text: .text-truncate:

<div class="card">
    <img class="card-img-top" />
    <div class="card-body">
        <h1 class="card-title text-center text-truncate" />
        ...
    </div>
</div>

These adjustments will help achieve results like:

https://i.stack.imgur.com/W6zP3.png


demo: https://jsfiddle.net/davidliang2008/uv4zbomL/34/


This may not be perfect, but it provides a starting point for your project.


Update: Ensuring Complete Title Display

To show the title entirely without truncation, use the flexbox technique by setting the .card-body as a flex container in column direction. This allows you to adjust the card header's margin bottom to push other content down. The recommended Bootstrap classes for this are: d-flex flex-column and mb-auto:

<div class="card">
    <img class="card-img-top" />
    <div class="card-body d-flex flex-column">
        <h1 class="card-title text-center mb-auto" />
        ...
    </div>
</div>

https://i.stack.imgur.com/OBFsc.png


demo: https://jsfiddle.net/davidliang2008/uv4zbomL/47/

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

Adjusting an image size using JQuery after resizing a canvas will only resize the image itself, not

How can I resize an image within a canvas using JQuery in a way that only the image is resized, not the entire canvas? function resizeImage(width, height){ var image = document.getElementById('resizeImage'), canvas = document.createEleme ...

The JavaScript-generated form element will not be included in the data submitted through the POST method

While it may appear that this question has been asked before, my specific inquiry seems to be unique as I have not found a similar answer in other threads. Therefore, I am initiating a new discussion. My issue revolves around a form which contains a link ...

What is the internal mechanism behind the operation of JavaScript function parameters?

As someone who is new to programming, I've been struggling to understand how parameters and arguments work behind the scenes. For example: function changeStuff(a) { return a = a * 10; } var num = 10; console.log(changeStuff(num)); / ...

Troubleshooting: ng-disabled not function properly in Angular.js

My goal is to only allow the button to be enabled if there is text in the textfield, but for some reason I am unable to make ng-disabled work: <form novalidate> <button type="submit" ng-click="add('+')" ng-disabled="bittext.$invalid ...

Caution: It is important that every child within an array or iterator is assigned a distinct "key" property

As a new developer in ReactJS, I have created a table using ReactJS on the FrontEnd, NodeJS on the BackEnd, and MySQL for the database. My goal is to retrieve data with a Select request on the table. For my frontend: class ListeClients extends Component ...

The Next Js API is experiencing difficulties resolving

I'm just starting out with back-end development so I could use some assistance with my current project. I am working on a next.js application that applies a black and white filter to an image when it is uploaded. In the index.js file, once a file is s ...

Executing database queries in a synchronous manner in JavaScript

let positionConfig = require('setting'); function retrieveConfig(element) { let setting; positionConfig.find({element: element}, function (err,docs) { console.log(docs[0].current); // show the value setting = docs[0].curr ...

Challenge with the behavior of dynamic elements in Jquery

Just a heads up, this is not a duplicate of : Event binding on dynamically created elements? I recently encountered some issues with jQuery dynamic event binding but eventually managed to resolve it. The syntax I was utilizing was : $(document.body).on(" ...

In what way can a container impact the appearance of a child placed in the default slots?

Visiting the vue playground. The main goal is for the container component to have control over an unspecified number of child components in the default slot. In order to achieve this, it's assumed that each child component must either hold a propert ...

Encountering a TypeError while trying to run Pythonshell on my Mac device

When I run a python script in node.js using python shell, it works perfectly on my Windows system. However, I encounter an error when trying to run the same thing on my Macbook: Error: TypeError: can't multiply sequence by non-int of type 'float ...

What is the best way to transform this into an HTML readable code?

While browsing through a template, I came across this code and I'm unsure of how to get it functioning. I've tried removing the comments, but unfortunately it doesn't seem to be working as expected. li.dropdown.navbar-cart ...

React component rendering twice due to width awareness

In a React component that I've developed, I have utilized ResizeObserver to track its own width. Within this component, two divs are rendered with each having a "flex: 1" property to ensure equal width distribution. Under certain conditions, such as w ...

Steps for correctly invoking a function based on input value conditions

Lately, I've been developing a new website geared towards serving as a platform for various travel agencies to showcase their tour packages. The homepage features a functional filter section that enables users to search for offers based on different ...

Organize images with overlays to the center of the page

I need help centering a group of pictures (a 3x3 table) on my webpage. I was able to center them before adding image overlays, but now the images are showing up in the top left corner of the page. How can I group and center them, and how do I specify the i ...

Display the number of rows per page on the pagination system

Looking for a way to add a show per page dropdown button to my existing pagination code from Mui. Here's the snippet: <Pagination style={{ marginLeft: "auto", marginTop: 20, display: "inline-b ...

Viewing the JSON Data

Support: $scope.createTimeSlots = function(interval, field) { var startingTime = moment().hours(8).minutes(0); field.timeslots = []; for (var i = 0; i < interval; i++) { $scope.intervals = 60; field.timeslots.push(startingTi ...

Lower the placement of Glyphicons

I have recently implemented a custom font on my website. Unfortunately, this font is not standard and its alignment is off. As a result, when I use this font with Twitter Bootstrap glyphicon, they do not appear in the same line. Is there a way to adjust t ...

Automatically selecting a row within Material-UI's data grid using React code

Currently, I am in the process of developing a React web application and utilizing DataGrid from Material-UI by Google. The grid displays based on the user's selection from a select list (e.g., if the select list consists of fruits and the user choose ...

Is there anyone available who can assist me in removing records from my Sequelize database?

I attempted to implement the code snippet below after coming across it on a popular platform, but for some reason, it doesn't seem to be functioning as expected. Posts.delete({ where: { createdAt: { isAfter: "2016-09-11" } } }) My goal is to remove ...

What is the process for implementing custom CSS styles in Cognos?

I've been working on creating Cognos reports and I'm looking to change the overall design of some specific ones (prompt pages and report pages). Is there a way for me to use different custom CSS files for each individual report? If that's ...