Ensure all divs have equal heights based on the tallest one, without compromising the responsiveness of the layout

I'm facing a challenge with my webpage that consists of multiple divs placed next to each other, each containing an image and text. Due to varying content lengths, the height of these divs ends up being different. Is there a way, without manually setting heights, to make all divs match the height of the tallest one while keeping the layout responsive? I tried using flexbox within a container which worked but disrupted the responsiveness - the divs wouldn't adjust their width based on browser size.

I attempted some jquery solutions found online, but for reasons unknown to me, they didn't work. If anyone has a solution, I'm willing to give it another shot.

The current page layout looks like this:

I encountered issues with the tablet layout not functioning properly without having a separate col-m-1 class. Since I lack experience with responsive design, I relied on W3C tutorials to guide me through this process.

Answer №1

You were on the right track using flex - The missing piece was including flex-wrap in your container:

@charset "utf-8";

/* CSS Document */

.container {
  display: flex;
  flex-direction: rows;
  flex-wrap: wrap;
}
* {
  box-sizing: border-box;
}
[class*="col-"] {
  padding: 15px;
  border: 1px solid red;
  text-align: center;
}
.clear {
  clear: both
}
html {
  font-family: Verdana, Geneva, sans-serif;
}
p {
  font-size: 11px
}
a,
a:hover,
a:active,
a:visited {
  color: #ffffff;
}
a.textlink,
a.textlink:hover,
a.textlink:active,
a.textlink:visited {
  color: #000000;
}
/* For mobile phones: */

[class*="col-"] {
  width: 100%;
}
@media only screen and (min-width: 600px) {
  /* For tablets: */
  .col-m-1 {
    width: 50%;
  }
}
@media only screen and (min-width: 768px) {
  /* For desktop: */
  .col-1 {
    width: 20%;
  }
}
img {
  max-width: 100%;
  height: auto;
}
<div class="container">
  <div class="col-1 col-m-1">
    <img src="some/image/path" />
    <br />Some text
    <br />And more text
    <br />And more text</div>
  <div class="col-1 col-m-1">
    <img src="some/image/path" />
    <br />Some text
    <br />And more text</div>
  ... Remaining code blocks ...
</div>

Above, I have included the container class and eliminated float left from the col class.

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

Finding it difficult to grasp the concept of asynchronous functions in NodeJS

I've been grappling with this NodeJS challenge for a good 6 hours already. Currently, I'm working with NodeJS along with Express and MongoDB. In my database, there are two collections - Listings and Categories. Each listing is linked to a categ ...

A tool for Google Chrome that can retain data until the browser is shut down

Looking to create a chrome extension that has the ability to play music continuously. Unfortunately, current chrome extensions stop playing as soon as users navigate away from or minimize the browser. I have attempted using background pages with limited su ...

CSS-only: Align items in flexbox column with equal width and centered position, without the need for a wrapper

https://i.stack.imgur.com/vAJv2.png This particular challenge involves creating a responsive mobile menu. In this design, the width of all children is determined by the longest child element. The CSS should ensure that the .index class spans the full wi ...

Tips for positioning tables on a page

I have 4 tables and a submit button. How can I make them more compact? Maybe like this: </img> This is my HTML code: <body> <form action="/cgi-bin/form.py" id="myform"> <table class="table-fill"> ... ...

Updating Vue component property when Vuex store state changes: A step-by-step guide

As I work on developing a straightforward presentation tool using Vue js and Vuex to manage the app state, I am facing a challenge in implementing a feature that tracks changes in the presentation such as title modifications or slide additions/removals. Cu ...

Can you effectively leverage a prop interface in React Typescript by combining it with another prop?

Essentially, I am looking to create a dynamic connection between the line injectComponentProps: object and the prop interface of the injectComponent. For example, it is currently set as injectComponentProps: InjectedComponentProps, but I want this associat ...

What is the best way to show or hide a child element when I hover over its parent?

Here is a snippet of HTML code for you: <style> .icon {display:none;} </style> <ul> <li>ABC <i id="abc" class="icon">x</i></li> <li>DEF <i id="def" class="icon">x</i></li> <l ...

Images stored in a WAR file

While this question may seem familiar, it's actually a unique situation. In Eclipse, within the WebContent folder, I have various directories such as images, jsp, WEB-INF, and META-INF. Testing the page using the Tomcat instance within Eclipse shows t ...

Strategies for resolving duplicate jQuery code in my project

Trying to simplify my jQuery code that handles video selection and playback functionality. Users can click on a thumbnail or button to play a specific video, with the title of the video changing accordingly. Despite achieving the desired outcome, the cur ...

Sustain unbroken websocket connection with Discord using Node.js

I've been working on developing a Discord bot using the raw API, but I've encountered an issue where the bot stops functioning after some time. I suspect that this is due to neglecting to maintain the websocket connection. How can I ensure that ...

RequestDispatcher.forward() does not work when servlet is invoked through an Ajax POST request

My login page involves user authentication through the firebase and sending the request to a servlet. When I click the submit button with correct credentials, the firebase authentication works, the servlet is called but an error is displayed in the browser ...

Refresh the Datatable with the click of a button

Despite my efforts and multiple attempts at different solutions, I am unable to get this particular issue resolved. It seems that my lack of experience with javascript/UI is hindering me from achieving the desired outcome. The background function in quest ...

Looking to extract the hidden value from an HTML input field using Selenium

Unable to retrieve the value of a hidden element in HTML, even though it is displaying. Seeking assistance in accessing the value despite the type being hidden. <input type="HIDDEN" label_value="Sub Reference" title="Sub Reference" id="ACC_NO" dbt="BK_ ...

Display Title Tag on Hover Effect using jQuery

I have currently utilized jquery to hide my title tags using the following code snippet: /** To hide the title tag that displays on hover **/ jQuery('document').ready(function($){ $('[title]').removeAttr('title'); }); ...

When accessing the defaultValue property of a select element, it will result in

Here is a typical HTML dropdown menu: <select name="email" id="email"> <option value="2" selected="selected">Before redirecting to PayPal</option> <option value="1">After payment is successful</option> <opti ...

Switching a class component to a functional component with react hooks (specifically useRef) - tips for preventing the dreaded "undefined" error

I have a code snippet that works as a class component and I'm trying to convert it into a functional component using the react-rewards library. Class component (working): import { Checkbox } from "@chakra-ui/react"; import React, { Compone ...

Issues arise when a questionnaire is duplicated

Currently, I am working on a questionnaire that involves the cloning feature in jQuery using .clone(). The questions are answered using checkboxes with options for yes or no. These checkboxes are placed within a table and controlled by the following script ...

Validating HTML Forms Using PHP

I am experimenting with a basic HTML login form, but I can't seem to get it to function properly. This is all new to me as I am just starting out with PHP programming. Any assistance would be greatly appreciated! <?php $correctPassword = 'ho ...

Tips for inserting a logo in the center of a QR code using Node.js

I'm currently working on designing a logo and attempting to incorporate it into the center of a QR code. While I've been successful in generating the QR code, I'm facing challenges in getting the logo to appear in the middle. I've tried ...

Transferring information between different collections in MongoDB using Mongoose can lead to encountering a VersionError

I'm facing an issue where Mongoose is unable to find a matching document with the id when transferring data from one collection to another. On my website, users search for classes in a Mongo DB collection called "classes." Once they find a class succ ...