What is the formula for determining the grid width when an item exceeds the column size?

I am working with a grid that matches the size of an image, which can be adjusted to be both smaller and larger in size.

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

Within this grid, I have 6 items.

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

Each item is wider than the columns in the grid.

In order to achieve the desired width for the grid as shown in the image, how should I calculate it?

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

tailwind.config = {
  theme: {
    extend: {
      zIndex: {
        1: 1,
        2: 2,
        3: 3,
        4: 4,
        5: 5,
        6: 6,
        7: 7,
        8: 8,
        9: 9,
      }
    }
  }
}
<script src="https://cdn.tailwindcss.com"></script>

<div class="w-64 bg-red-200 p-4">
  <div class="grid grid-cols-6 relative">
    <div class="absolute w-20 aspect-[2/3] rounded-sm inline-block overflow-hidden relative z-10">
      <img src="https://www.themoviedb.org/t/p/original/wZp8xcADdOZ0FK6FEEtrKXjjdKJ.jpg" alt="" class="w-full h-full">
    </div>
    <div class="absolute w-20 aspect-[2/3] rounded-sm inline-block overflow-hidden relative z-9">
      <img src="https://www.themoviedb.org/t/p/original/wZp8xcADdOZ0FK6FEEtrKXjjdKJ.jpg" alt="" class="w-full h-full">
    </div>
    <div class="absolute w-20 aspect-[2/3] rounded-sm inline-block overflow-hidden relative z-8">
      <img src="https://www.themoviedb.org/t/p/original/wZp8xcADdOZ0FK6FEEtrKXjjdKJ.jpg" alt="" class="w-full h-full">
    </div>
    <div class="absolute w-20 aspect-[2/3] rounded-sm inline-block overflow-hidden relative z-7">
      <img src="https://www.themoviedb.org/t/p/original/wZp8xcADdOZ0FK6FEEtrKXjjdKJ.jpg" alt="" class="w-full h-full">
    </div>
    <div class="absolute w-20 aspect-[2/3] rounded-sm inline-block overflow-hidden relative z-6">
      <img src="https://www.themoviedb.org/t/p/original/wZp8xcADdOZ0FK6FEEtrKXjjdKJ.jpg" alt="" class="w-full h-full">
    </div>
    <div class="absolute w-20 aspect-[2/3] rounded-sm inline-block overflow-hidden relative z-5">
      <img src="https://www.themoviedb.org/t/p/original/wZp8xcADdOZ0FK6FEEtrKXjjdKJ.jpg" alt="" class="w-full h-full">
    </div>
  </div>
</div>

Answer №1

You might want to try using the width: max-content property with the w-max class from Tailwind CSS. According to max-content, it defines the maximum intrinsic width or height of the content.

tailwind.config = {
  theme: {
    extend: {
      zIndex: {
        1: 1,
        2: 2,
        3: 3,
        4: 4,
        5: 5,
        6: 6,
        7: 7,
        8: 8,
        9: 9,
      }
    }
  }
}
<script src="https://cdn.tailwindcss.com"></script>

<div class="w-max bg-red-200 p-4">
  <div class="grid grid-cols-6 relative">
    <div class="absolute w-20 aspect-[2/3] rounded-sm inline-block overflow-hidden relative z-10">
      <img src="https://www.themoviedb.org/t/p/original/wZp8xcADdOZ0FK6FEEtrKXjjdKJ.jpg" alt="" class="w-full h-full">
    </div>
    <div class="absolute w-20 aspect-[2/3] rounded-sm inline-block overflow-hidden relative z-9">
      <img src="https://www.themoviedb.org/t/p/original/wZp8xcADdOZ0FK6FEEtrKXjjdKJ.jpg" alt="" class="w-full h-full">
    </div>
    <div class="absolute w-20 aspect-[2/3] rounded-sm inline-block overflow-hidden relative z-8">
      <img src="https://www.themoviedb.org/t/p/original/wZp8xcADdOZ0FK6FEEtrKXjjdKJ.jpg" alt="" class="w-full h-full">
    </div>
    <div class="absolute w-20 aspect-[2/3] rounded-sm inline-block overflow-hidden relative z-7">
      <img src="https://www.themoviedb.org/t/p/original/wZp8xcADdOZ0FK6FEEtrKXjjdKJ.jpg" alt="" class="w-full h-full">
    </div>
    <div class="absolute w-20 aspect-[2/3] rounded-sm inline-block overflow-hidden relative z-6">
      <img src="https://www.themoviedb.org/t/p/original/wZp8xcADdOZ0FK6FEEtrKXjjdKJ.jpg" alt="" class="w-full h-full">
    </div>
    <div class="absolute w-20 aspect-[2/3] rounded-sm inline-block overflow-hidden relative z-5">
      <img src="https://www.themoviedb.org/t/p/original/wZp8xcADdOZ0FK6FEEtrKXjjdKJ.jpg" alt="" class="w-full h-full">
    </div>
  </div>
</div>

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

css Issue with the "left" property

Is it possible to center the left side (left border) of a child div within its parent div? I tried using left: 50% in the CSS for the child div, but it doesn't seem to be working. Can anyone explain why? <div id="outher"> <div id="inner ...

What is the best way to customize my menu so that the currently selected element stands out with a distinct color?

I'm struggling with customizing the background color of the active page due to complex HTML structure. I'm using responsive twitter bootstrap (2) and facing challenges. To view all tabs at the top, you need to stretch the viewing window. Below is ...

What is the best way to display only a specific container from a page within an IFRAME?

Taking the example into consideration: Imagine a scenario where you have a webpage containing numerous DIVs. Now, the goal is to render a single DIV and its child DIVs within an IFrame. Upon rendering the following code, you'll notice a black box ag ...

Encountering a problem while running npm build (PostCSS plugin postcss-purgecss needs PostCSS 8) on vuejs3 with tailwind

I'm currently in the process of developing an application using Vue.js 3 and Tailwind CSS. While testing some configurations before diving into the project, I encountered a specific error message when running npm run build: ERROR Failed to compile wit ...

Creating a checklist using HTML and CSS can be achieved by utilizing the <span> element and

I'm having trouble changing the color of a span box to red when I focus on a link. The span successfully changes color when activated, but nothing happens when I try to use the 'focus' pseudo-class. On click, different categories will displa ...

Why do my padding and font size fail to match the height of my container?

When setting the height of my boxes to match the height of my <nav>, I encountered overflow issues. Despite using a 10rem height for the nav and a 2.25rem font, calculating the padding as 10-2.25/2 didn't result in the desired outcome. Can someo ...

How can the front design of Material-UI's Card header be customized?

Currently, I am facing an issue with the Material-UI card header as the background color is affecting the readability of the default font. My aim is to use the typography prop h4 for the header, but I am struggling to achieve this. https://i.stack.imgur.c ...

How can I conceal child <div> elements when the parent div is resized?

Struggling to implement a zoom in/out feature on my web app using the jqueryUI slider. Having trouble handling cases where the parent div shrinks too much, causing issues with the child containers. <div class="puck originator inline-block" style="w ...

How to display only a portion of content using UI Bootstrap collapse feature

In my Angular.js application, I currently have a row of buttons that open up new routes to display partial views. Now, I need to modify some of these buttons to trigger a ui.bootstrap Collapse feature with the view inside it. The template code from the ui. ...

Issues with content overlapping within Bootstrap can arise when elements are

Struggling with my band website development using Bootstrap. Inexperienced in web design, I'm facing difficulties getting elements to align properly without slipping under each other. Looking for insights and suggestions on how to avoid manual CSS adj ...

Spartacus 3.3 - Unleashing the Full Potential of the Default Sparta Storefront Theme

Looking for advice on how to customize the default Spartacus Storefront theme (Sparta) by only overriding specific CSS vars. Any suggestions? I tried following the instructions provided at: https://github.com/SAP/spartacus/blob/develop/projects/storefront ...

Why is the inline-block element in the list displaying on two lines? The text contains a number, but does it affect the layout?

What could be the reason for 'Maroon 5' moving down to a second line? Despite adding extra characters and testing with an integer, the issue persists. <ul id="soundsLike"> <li>Foo Fighters</li> <li>Maroon 5</ ...

Adjusting height dynamically with CSS based on font size

Below is a link followed by a span element <a href="#" style="display:inline-block;font-size:900%">12</a> <span display="block">ACTIVE</span> The issue arises when the 'a' element does not have a specific height, causing ...

Automatically trigger a page reload using a jQuery function

Currently facing an issue with jQuery. I created a drop-down menu and would like it to expand when the li tag within the menu is clicked. Even though I am using the jQuery click function successfully, there seems to be a problem where the webpage refreshe ...

Using an overlay with figure-img in Bootstrap 4 is a visually appealing design

I need assistance with adding an overlay to only the bootstrap 4 figure-img. In order to achieve this, I inserted a div with the class overlay beneath the figure-img. Below is the code snippet: <div class="col-md-4"> <figure class="service tex ...

Positioning an Element on a Web Page in Real-Time

Trying to implement an Emoji picker in my React application, I have two toggle buttons on the page to show the picker. I want it to appear where the Toggle button is clicked - whether at the top or bottom of the page. The challenge is to ensure that the pi ...

How can I use jQuery to identify the numerical range within class/td/div elements and modify their CSS styles?

1# I need assistance in changing the CSS properties of a TD, Class, and div using a selector that specifies a specific number range. Specifically, I am looking to modify the css of torrent results with a seed count between 250-25000. Any torrents with a se ...

Adjusting the size of a Video/Image Slider to perfectly fit the screen dimensions (both width and height

I have been using a slider code to display my images and videos. The code can be found here: Code:https://codepen.io/1wdtv/pen/jbjZeb The issue I am facing is that the slider is only responsive in terms of width. This means that when resizing the browser ...

Class for making elements draggable using jQuery UI

Is it possible to use jQueryui's draggable/droppable combo and add a class to the dragged item when dropped into a specific container, rather than adding a class to the container itself? I've tried adding a class to the container, but that is not ...

Pondering the importance of the "zoom" feature in creating responsive designs

Currently, I am working on creating a responsive design using HTML and CSS. However, I have encountered an issue that I need help with: When resizing the window, the layout adapts perfectly. Similarly, when zooming in or out without resizing the window, e ...