Difficulties encountered with tailwind grid responsiveness on small screens

I'm encountering issues trying to implement a Tailwind grid on different breakpoints. I created a card in Next.js that I want to display in a grid layout. It looks fine on larger devices but doesn't adjust for medium/small ones as intended. The grid should initially have 4 columns, then transition to 2 on medium devices, and finally collapse into a single column on small devices. However, this behavior isn't happening.

Here is the Hero section responsible for rendering this grid:

const Hero = () => {
  return (
    <section>
      <div className='flex flex-row justify-between max-w-screen-xl items-center mx-auto p-4'>
        <div className='w-1/2 pt-0'>
          <Image src={Couple_Coder} alt="CodeCouple" className='h-auto'>
          </Image>
        </div>
        <div className='w-1/2 flex flex-col space-y-4 items-center self-center'>
          <div className='h-1/4'>
            <AnimatedText text="Some Text" className='!text-left !text-6xl'/>
            <AnimatedText text="Some Text" className='!text-left !text-6xl'/>
            <AnimatedText text="Some Text" className='!text-left !text-6xl'/>
          </div>
          <div className='mt-10 h-1/4'>
            <p className='my-4 text-base text-center font-medium pb-10'>
              Some Text!!!
            </p>
          </div>  
          <div className='h-1/4 flex flex-row space-x-4 mt-10 mb-8 pt-4 gap-3'>
            <button type='button' className='button-6'>Workshops</button>
            <button type='button' className='button-6 ml-4'>Discord</button>
          </div>
        </div>
      </div>
      <div className='grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 max-w-screen-xl gap-4 mx-auto'>
            <div className='col-span-1'>
                <AnimatedText text="Join Our Workshops" />
            </div>
            <div className='flex col-span-1 md:col-span-2  lg:col-span-4 md:justify-between lg:justify-between gap-4'>
                <Card />        
                <Card />
                <Card />
                <Card />
            </div>
        </div>
    </section>
  )
}

I also have a global layout applied to all children components:

export default function RootLayout({ children }) {
  return (
    <html lang="en">
      <body>
        <div className="overflow-hidden bg-site bg-cover bg-no-repeat bg-white border-gray-200 dark:bg-gray-100">
        </div>
        <Navbar />    
        <main className='app xl:p-24 lg:p-16 md:p-12 sm:p-8 bg-white border-gray-200 dark:bg-gray-100 '>
        
        {children}
      </main>
      </body>
    </html>
  )
}

Any insights into what might be going wrong?

My goal is to have 4 columns on large devices, switch to 2 columns on medium devices, and eventually go down to 1 column on small devices.

Thank you!

I've experimented with changing the classNames of the divs and adjusting the screen defaults in the Tailwind config file. I even tried setting my own breakpoint order from large devices to small, but unfortunately, none of these attempts have resolved the issue.

Answer №1

<div className='grid col-span-1 md:col-span-2  lg:col-span-4 md:justify-between lg:justify-between gap-4'>
     <Card />        
     <Card />
     <Card />
     <Card />
</div>

In this particular code excerpt, switch the flex to grid

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

Is there a way to refresh the animation on dougtesting.net?

I'm working with the dougtesting.net library to create a spinning wheel. I've been trying to figure out how to reset the animation once it finishes, but I can't seem to find any information on it. My goal is to completely clear all states so ...

What is the best way to remove an S3 object from a bucket within a Next.js application?

This marks my first experience with AWS S3. I am currently in the process of saving images (jpg/png etc.) on S3 and storing the URL in a database. The application is designed to track the user's session along with the S3 URL when they submit a picture ...

Why has my image suddenly increased in size?

As a mid-level backend developer, I pride myself on being able to solve problems independently. However, there is something about the act of writing out my issue that always seems to lead me towards a solution. It's like the concept of "rubber-ducking ...

Unable to set child element to match parent element's height in Internet Explorer

Attempting to make a child element of a table cell inherit the height and width of the table cell through CSS. Below is the HTML provided: <tr> <td> <div class="yellowDiv"></div> </td> <td></td> ...

Words existing outside of an element

Currently, I am developing a slider using Bootstrap, and I have encountered an issue where the text displays on the left instead of aligning to the center in relation to the elements. To see this issue in action, you can check out the live demo here: In ...

What's causing my struggle to override the bootstrap nav-link class in next.js?

I am facing an issue where I need to customize the active state of bootstrap .nav-link in the code snippet below: <li className="nav-item"> <a className={`${styles.navLink} nav-link`} role="tab" data-to ...

Zod faces a challenge while parsing environment variables in Nextjs 14 due to an unexpected error

I encountered an error while parsing my environment variables using zod in my Next.js 14 project: ZodError: [ { "code": "invalid_type", "expected": "string", "received": "undefined", ...

What is the best way to wrap a div in a vertical orientation?

I'm looking to create a vertical div around an image that fluidly changes width: |_________________| | |XXXXXX| | | |XXXXXX| | | |XXXXXX| | | |XXXXXX| | | |XXXXXX| | | |XXXXXX| | |-----------------| The cont ...

Why is my Bootstrap row exceeding the page width when I resize it?

As a newcomer to Bootstrap, I have been following tutorials to learn more about it. Currently, I am attempting to recreate the layout of Google's homepage. However, I am facing challenges with the grid system's responsiveness. I have managed to ...

Try using Bootstrap 4 Carousel columns instead of the traditional carousel-item

Is it possible to use Bootstrap to display grid columns or rows within a Carousel instead of carousel-items? The concept involves having intricate grid column structures that rotate like carousel-items. For instance, if we have the following grid: <div ...

Tips for arranging content below a stationary header

I have a question about placing two divs below the header and making it fixed. I am experiencing an issue where my divs are not visible because they are going inside the fixed element. Can someone offer some assistance on how to solve this problem without ...

Safari does not support SVG fill pattern, unlike Firefox and Chrome

Having an issue with Safari 6.1.5 not displaying a pattern in an SVG rectangle. After simplifying the code, here is the test case: <html> <head> <style> .patterned { fill: url("#myid") none; stroke:blue} ...

What is the best way to include a final tag on its own line?

I'm trying to add a new line for "Payment Remaining", but it doesn't go to the next line as expected. I need the final text to be on a separate line, Payment Remaining #authorization-wizard-start-work .btn-group label.active { color: #009 ...

Tips for boosting page speed in next.js

Our current setup involves Next JS as our frontend framework and Wordpress for content management. However, we are encountering significant delays in page rendering due to the time it takes to fetch headers and footers data from Wordpress using a graphql q ...

Is there a way to dynamically update an image in my CSS without having to refresh the page?

Is it possible to update an image in CSS dynamically using the value of console.log without reloading the page? function reply_click(clicked_id){ $(function() { $.ajaxSetup({ headers: { 'X-CSRF-TOKEN': ...

Creating dynamic grids in React.js by utilizing HTML

Currently, I am tackling one of the projects on FCC which is the Game of Life. Prior to diving in, my focus is on figuring out how to render a grid on the page. I aim to modify the table dimensions while ensuring it fits neatly within its container. The ...

Installation of Shadcn UI results in the disruption of Tailwind CSS

The Shadcn UI was performing well for a few weeks until yesterday. When I ran my NextJS app on my local host, the tailwind styling stopped working. To troubleshoot, I created a new NextJS 13 app in a different location, and everything worked fine - tailwin ...

Eliminating the need for horizontal scrolling in the window causes a change in the height of an internal DIV element

Check out this snippet of code, a simplified version of a larger piece: html, body { margin: 0 !important; padding: 0 !important; /* overflow-x: hidden; /* uncomment this line */ } .app { position: relative; width: 100%; text-align: center !important; } ...

Angular 2.0 in conjunction with D3.js does not style SVG elements using CSS

Currently, I am utilizing Angular 2.0 TypeScript along with the d3.js library to create graphics. My main focus is on applying CSS to the axis (especially shape-rendering: crispEdges;). Do you have any suggestions? Check out the code below: var vis = d3 ...

The hover effect on the menu button is not covering the entire button when the screen is resized

It appears that I am encountering a problem with the hover functionality. When my screen is at full size, hovering over a menu option causes the entire background color to change. However, upon resizing the screen, only a part of the background color chang ...