What steps can I take to ensure this grid adjusts seamlessly across different screen sizes

I'm struggling to create a responsive grid layout and I need some guidance. How can I make this grid responsive? Specifically, I want it to switch to a one-column layout when the browser size is reduced. I've attempted using media queries and various frameworks, but I haven't achieved the desired result yet. Any help would be greatly appreciated. Below is the code snippet:

CSS:

.container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr 1fr;
    gap: 5px 5px;
    grid-auto-flow: row;
    grid-template-areas:
      "farmhouseburger quinoablack"
      "chocolatemilkshake standardburger"
      "checkout perfect";
  }


  
  .farmhouseburger {
        grid-area: farmhouseburger;
        background: url(imgs/farmhouse.jpg) no-repeat center center fixed; 
        -webkit-background-size: cover;
        -moz-background-size: cover;
        -o-background-size: cover;
        background-size: cover;
        text-align: center;
    }
  
  .quinoablack {
        grid-area: quinoablack;
        background: url(imgs/quinoa.jpg) no-repeat center center fixed; 
        -webkit-background-size: cover;
        -moz-background-size: cover;
        -o-background-size: cover;
        background-size: cover;
        text-align: center;
     }
  
  .chocolatemilkshake {
       grid-area: chocolatemilkshake;
       background: url(imgs/milkshakeback.jpg) no-repeat center center fixed; 
        -webkit-background-size: cover;
        -moz-background-size: cover;
        -o-background-size: cover;
        background-size: cover;
        text-align: center;
    }
  
  .standardburger {
      grid-area: standardburger;
      background: url(imgs/standard.jpg) no-repeat center center fixed; 
        -webkit-background-size: cover;
        -moz-background-size: cover;
        -o-background-size: cover;
        background-size: cover;
        text-align: center;
    }
  
  .checkout { 
      grid-area: checkout;
      background: url(imgs/checkout.jpg) no-repeat center center fixed; 
        -webkit-background-size: cover;
        -moz-background-size: cover;
        -o-background-size: cover;
        background-size: cover;
        text-align: center;
    }
  
  .perfect { 
      grid-area: perfect;
      background: url(imgs/barbecue.jpg) no-repeat center center fixed; 
        -webkit-background-size: cover;
        -moz-background-size: cover;
        -o-background-size: cover;
        background-size: cover;
        text-align: center;
    }

HTML:

<div class="container">
        <div class="farmhouseburger">
                <div>
                    <h3 class="h3grid">NEW</h3>
                    <h1>FARMHOUSE<br>BURGER</h1>
                    <p>This burger’s name explains itself. Of course, you can<br>also top it with crisp lettuce, tomatoes, ketchup,<br>barbecue sauce and anything else.</p>
                    <h1>$2.49</h1>
                    <button class="buttongrid">ORDER NOW</button>
                </div>
        </div>
        <div class="quinoablack">
            <div>
                <h3 class="h3grid">NEW</h3>
                <h1>QUINOA & BLACK<br>BEAN BURGER</h1>
                <p>We can’t think of a better way to celebrate summer than<br>with these omg-worthy hamburgers. Plus, try our over-<br>the-top creative cheeseburgers.</p>
                <h1>$3.99</h1>
                <button class="buttongrid">ORDER NOW</button>
            </div>
        </div>
        <div class="chocolatemilkshake">
            <div>
                <h3 class="h3grid">NEW</h3>
                <h1>CHOCOLATE<br>MILKSHAKE</h1>
                <p>Milkshakes always taste good if you are a chocolate lover.<br>You can throw one together with a cream or experiment<br>with all kinds of extra flavors.</p>
                <h1>$2.49</h1>
                <button class="buttongrid">ORDER NOW</button>
            </div>
        </div>
        <div class="standardburger">
            <div>
                <h3 class="h3grid">NEW</h3>
                <h1>STANDARD<br>BURGER<br>MEAL</h1>
                <p>These incredible burger meal offer a unique twist to the<br>classic hamburger, incorporating ingredients like<br>pimento cheese and sesame.</p>
                <h1>$4.99</h1>
                <button class="buttongrid">ORDER NOW</button>
            </div>
        </div>
        <div class="checkout">
            <div>
                <h3 class="h3grid">NEW</h3>
                <h1>CHECKOUT OUR<br>CATERING MENU</h1>
                <p>Throwing the party is never been easier. Order now and<br>let us spice up your party. Burger meals, french fries and<br>cheeseburgers will cheer up your friends.</p>
                <h1>$13.99</h1>
                <button class="buttongrid">ORDER NOW</button>
            </div>

        </div>
        <div class="perfect">
            <div>
                <h3 class="h3grid">NEW</h3>
                <h1>HOW TO MAKE A<br>PERFECT BURGER</h1>
                <p>We will tell you a little secret. Mixing best quality steak<br>and pork and serves them on homemade herb-butter<br>rolls is the best version we know.</p>
                <h1>$5.99</h1>
                <button class="buttongrid">ORDER NOW</button>
            </div>
        </div>
      </div>

Answer №1

Instead of using grid area, I have implemented the following line of code:

/grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));/

I conducted a test on a small screen size of 390x844 and it performed well.

This is the CSS code snippet:


        .container {
            max-width: 1200px;
            margin: 0 auto;
            display: grid;
            grid-gap: 1rem;
            grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
        }
  
        .farmhouseburger {
            background: url(imgs/farmhouse.jpg) no-repeat center center fixed; 
            -webkit-background-size: cover;
            -moz-background-size: cover;
            -o-background-size: cover;
            background-size: cover;
            text-align: center;
        }
        
        .quinoablack {
            background: url(imgs/quinoa.jpg) no-repeat center center fixed; 
            -webkit-background-size: cover;
            -moz-background-size: cover;
            -o-background-size: cover;
            background-size: cover;
            text-align: center;
        }
        
        .chocolatemilkshake {
            background: url(imgs/milkshakeback.jpg) no-repeat center center fixed; 
            -webkit-background-size: cover;
            -moz-background-size: cover;
            -o-background-size: cover;
            background-size: cover;
            text-align: center;
        }
        
        .standardburger {
            background: url(imgs/standard.jpg) no-repeat center center fixed; 
            -webkit-background-size: cover;
            -moz-background-size: cover;
            -o-background-size: cover;
            background-size: cover;
            text-align: center;
        }
        
        .checkout { 
            background: url(imgs/checkout.jpg) no-repeat center center fixed; 
            -webkit-background-size: cover;
            -moz-background-size: cover;
            -o-background-size: cover;
            background-size: cover;
            text-align: center;
        }
        
        .perfect { 
            background: url(imgs/barbecue.jpg) no-repeat center center fixed; 
            -webkit-background-size: cover;
            -moz-background-size: cover;
            -o-background-size: cover;
            background-size: cover;
            text-align: center;
        }

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

The offscreen div triggers the window to enlarge exclusively in the mobile browser

As I work on creating a website for an anti-bullying program at my school, I decided to add a fun and animated background. The idea of moving clouds caught my attention, so I incorporated them into the design. Initially, I encountered a bug where offscreen ...

Is there a way to place a button in the top-right corner next to my Bootstrap 5 card?

Can someone help me figure out how to position a button on the top right corner next to my bootstrap card? Here's the code I have so far: <div className="row p-5 m-2"> {savedEpisodes?.map((saved) => { return ( ...

Navigate files on a Windows server remotely using a Linux Apache web server by clicking on a browser link

After setting up an apache webserver on Linux Debian and successfully creating an intranet, I encountered a challenge. The intranet is designed to display tables with data from sql queries using php and mysql. However, I wanted to include a hyperlink withi ...

Ben Kamens has developed a new feature in jQuery Menu Aim where the sub menu will not reappear once it

While exploring Ben Kemens’ jquery-menu-aim, I came across a demonstration on codepen. The code on codepen allows smooth transition from the main menu to the sub menu, but if you move away completely, the submenu remains visible and doesn't disappe ...

The navigation bar dropdown displaces items from the navbar on smaller screens

The image illustrates my point perfectly Although I am attempting to move it within the navbar on a smaller screen, it doesn't seem to be working. ...

Showcasing a newly added document featuring both a visual representation and a direct file access link

I am currently facing a challenge with my website where I have 5 images that are linked to files. I recently added the functionality to upload files to a directory called "uploads". Now, I want these uploaded files to be displayed on the site using corresp ...

Obtain the location of the image source from a text file within an HTML document

I need to create a slideshow displaying a sequence of images. The path to these images will be stored in a text file. How can I read the image paths from the text file? Currently, I have hardcoded code like the example below: <div class="mySlides fade" ...

Make sure to adjust the original router URL when the application is being run within iframe or object

Currently, I am embedding Vue apps within object tags or iframes of a master Vue app container. Initially, I set up a file server that serves the container or the requested sub-app to render inside a div. Below, I will show the necessary routing of my Nod ...

Maintaining consistent margins on both the left and right sides can be achieved easily using TailwindCSS

I have been trying to figure out how to center a fixed element on my screen, but all the solutions I've found so far are not working for me. Originally, I tried fixing my div in the center of the screen using `mx-[40%] mt-[10%]', but it only look ...

Creating Carousel Images with Rounded Corners using Bootstrap 5

The left corners of the carousel images are rounded, but during the sliding animation, they become pointed again. https://i.sstatic.net/syoPk.png #carouselCoulumn1Neutral { padding-left: 40px; padding-top: auto; padding-right: 20px; paddi ...

Having trouble with Laravel 5.8 Bootstrap integration within JQuery?

i found a helpful resource at everything seems to be working well in the view, but i'm encountering issues when trying to implement it in JQuery. if anyone has suggestions on how to resolve this problem, please let me know. here is the PHP code for ...

Two rows of images with a horizontal scroll bar

Looking to create a grid of images where each image is displayed side by side. The goal is to have a fixed width and height for the container, with a horizontal scrollbar appearing if there are 12 or more images in the grid. Additionally, any overflow imag ...

Reorganize a list based on another list without generating a new list

Among the elements in my HTML list, there are items with text, input fields, and tables. I also have a specific order list like [3,1,2,0]. Is it feasible to rearrange the items in the HTML list on the page based on this order list without generating a new ...

Content below divs that are fixed and absolutely positioned

I have a design layout similar to this (a small snippet) and I am facing an issue where the text within .content is not clickable. The positioning of #gradient is fixed due to the background image, and #empty has an absolute position to cover the entire bo ...

How can the printing of content be adjusted when the browser zoom function is activated?

Is there a way to prevent the content from zooming when printing while the browser is zoomed in? The goal is for the printing (using iframe) to remain unchanged even if the browser is zoomed. I attempted: document.body.style.transformOrigin = 'top le ...

Why does my 'click' event listener only work for the first two <li>'s and not the others?

I am new to programming and recently achieved success with my 'click' eventListener. When clicking on the first two li elements within the ul, the class of the div toggles on and off as expected. However, I encountered an issue where clicking on ...

`Understanding Unique Identifiers in HTML: Questions on Element Naming`

Is it problematic to use a space character in an element ID? For example, like this: <li id='something with spaces'>Test123</li> I typically avoid using spaces in IDs, but I've encountered a situation where it might be necessar ...

The Element should take up the entire page with the exception of a 20px margin

I am struggling to create an element that covers the entire page except for a 20px margin on all sides. I have tried implementing a solution using this code, which works in webkit browsers and Firefox but seems to have issues with Internet Explorer (10) an ...

Which takes longer to render: individually drawn images placed via absolute positioning, or one complete image?

I currently have a collection of "cards" on my website that are jpg images, but I am considering switching to an HTML/CSS solution. This change would involve placing numerous small icons on a background and adding stylish text on top. My concern is determ ...

Why is the image not resizing based on the dimensions of its container?

I have enclosed an image tag within a div tag. <div className="product-details-container"> <div className="product-img-wrapper"> <ListingCardImage imgAlt={product.title} imgSrc={product.image}/> ...