Make all grid items in TailwindCSS uniform height

My goal was to design a grid using Tailwind CSS where all items would have equal height.

However, I encountered an issue when the children had varying content lengths, causing their background color not to fill the entire cell:

https://i.sstatic.net/nyfXj.png


This is the grid markup I used:

<div class="grid grid-cols-2 gap-4 auto-rows-max">{ITEMS}</div>

And here's the markup for the individual item:

<div class="rounded-md overflow-hidden ring-1 ring-blue-600 ring-opacity-20">
  <div class="bg-red-200 p-6 flex flex-col justify-between ">{BODY}</div>
</div>

I initially believed that using auto-rows-max would solve the problem, but it did not work as expected.

You can view an interactive example here: https://play.tailwindcss.com/dlgGmz41dA

Answer №1

The background color is currently being applied one tag too late. To ensure that each grid cell has a full color background regardless of content length, simply move the bg-red-200 class up to the div with rounded-md overflow-hidden....

Here is the correct item markup:

<div class="bg-red-200 rounded-md overflow-hidden ring-1 ring-blue-600 ring-opacity-20">
  <div class="p-6 flex flex-col justify-between ">
   ...
  </div>
</div>

You can also test this on Tailwind Play at https://play.tailwindcss.com/Lf7nF97Be1

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

What steps should be taken to position the Header and search bar in the middle of the screen?

How can I center the title and search bar on a website using Bootstrap? I've tried adding my-auto, but it doesn't work. Any suggestions?https://i.sstatic.net/3uuhT.png <!DOCTYPE html> <html lang="en"> <head> < ...

Enable the automatic resizing of a div element

This div features inside: <div class="PF"> <img src="img" class="FollowerPic"> <span>Name</span> <div class="Text"></div> <div class="readURL"> ...

What is the process for inserting a hyperlink within an image?

How can I create a certificate in jpg/bmp/png format for my web application? Is it possible to encode a URL inside the logo so that when clicked, it redirects to the online profile? ...

When attempting to achieve a CSS percent width, the output is given in pixels instead. I am in search of a solution where the percentage remains the same as the

My styling is set as a percentage, like this: <style> #somediv {width:70%} </style> <div id="somediv"></div> jQuery's css() function returns the result in pixels $(document).ready(function(){ var css = $("#somediv").css( ...

Uninterrupted Carousel Experience in Bootstrap 4 (Seamless slide transition)

I'm having trouble figuring out how to make a carousel run continuously without pauses between slides. Here's an example of what I'm working with on codeply: .carousel-img-small { width: 80px; height: 80px; margin-right: 2%; } .car ...

Refresh the block's content seamlessly without the need for a page reload

Within the index.html page There exists a block called content that contains various content blocks. An additional navigation menu with numerous links is present. It is important that when you click on a menu link, the content within the content block re ...

Exploring the Depths of Angular Reactive Forms with Recursion

Dealing with recursion and form groups app-root.component.html <div [formGroup]="form"> some content <app-root></app-root> </div> Is it possible to implement the same form group and form controls in my recursive structure? For ex ...

How to align all children at flex-start while positioning one child at the end?

I am currently working on a flex container that has 3 children. My goal is to have all the children align at flex-start, with the final child positioned at the bottom of the container. Can align-content be combined with align-self to achieve this layout? ...

JavaScript Number Conversion with parseInt()

Struggling to execute a calculation that fills a text box based on an onblur event. Unfortunately, I keep getting NaN as the result. Since I am not very familiar with JavaScript, any guidance will be greatly appreciated. Please note that I am mainly focus ...

What is the best way to customize the font in a Marquee code using HTML?

I am a beginner to coding and have been searching for HTML code to create an infinite marquee text. After hours of looking, I found one on by inspecting the elements on their page. When I copied and pasted the code into my site, the font didn't displ ...

Is there an alternative to using CSS units of measurement when using the .css() method?

Is there a way to use .scrollTop() and .css() to adjust the margins of an element so that it floats up only when the page is scrolled, but stops at a certain margin value? I want the element to float between specific values while scrolling. The issue I am ...

Passing a parameter from AJAX to PHP

const studentNumber = $('#studno').val(); $(document).ready(function () { $('.go').click(function () { $('.inup').load('prochat.php', { studno: studentNumber }); }); }); I've ...

Files on video input are now accepting audio attribute

Currently, I am adding a file upload feature to my application. I have created input fields for various types of media. <label>Images<input type="file" accept="image/*"/></label> <label>Videos<input type="file" accept="video/*"/ ...

The line break is being disregarded by jQuery's insertBefore function

In my simple HTML, I have a div with a limited width. Inside are several span tags styled with nowrap. Here is the CSS: .content { width: 50%; margin: 10px; padding: 10px; border: 1px solid black; } .adder { color: blue; cursor: po ...

Adjust the font style based on the length of the text input

Can anyone assist me in changing the font size of an input field using JavaScript based on the number of characters typed? By default, the font size is set to 16px, but I would like it to decrease to 12px once more than 10 characters are entered. This is ...

The font is functioning properly in digital screen formats, however, it is not displaying correctly in

I have encountered an issue where the code below works on screen media but not in print media: <style type="text/css"> @font-face { font-family: dinregular; src: url('/images/templateImages/template9/din-regular-italic.ttf') } < ...

Best approach for routing using express

My current project involves using Express to develop a small website. Here is the code snippet I am working with: var package_express = require('express'); var app = package_express(); app.get("/", function(req, res){ res.sendFile(__dirname ...

Having trouble with my Bootstrap 4 navbar button - what am I doing wrong?

After conducting research online, I found myself unable to resolve my issue due to my lack of proficiency in English. I apologize for any confusion caused and would like to revisit the topic. The problem lies with my navbar toggle that is not functioning ...

Angular 1.5 - Component for fetching HTML content with dynamic data

Help needed with using Angular Component method. Developing a main html file with its main controller containing a JSON list of client data: clients: [{ "name": "John Jackson", "age": "21", "hair": "brown", }, { "name": "Janet Doe", ...

Insert a line break above and below every <h1> tag

Hey there, I'm just starting out with CSS and I might have some beginner questions. I want to add a line break at the top of my post before and after my h1 tags. I may be going about this the wrong way. It's possible that I need some padding at t ...