Problem with ineffective responsive CSS on mobile devices

Is there anyone who can assist me with this issue? I have set up a CSS grid that works properly above 768px when the min-width is specified. However, as I scale below that threshold, the layout remains unchanged and the media tag doesn't seem to take effect. If I switch from min-width to max-width, the formatting is correct for screens below 768px but not for those above that size.

HTML

 <html>
        <head>
            <title>Responsive Design with CSS Media Queries</title>
            <link rel='stylesheet' href='style.css'/>
        </head>
        <body>
            <div class="grid-container">
                <div class="grid-item-1"></div>
                <div class="grid-item-2"></div>
                <div class="grid-item-2"></div>
                <div class="grid-item-2"></div>
                <div class="grid-item-2"></div>
                <div class="grid-item-3"></div>
                <div class="grid-item-4"></div>
                <div class="grid-item-5"></div>
                <div class="grid-item-6"></div>
            </div>
        </body>
    </html>

CSS

    *{
    margin: 0;
    padding: 0;
    font-family: sans-serif;
    font-weight: lighter;
}

@media (min-width: 769px) and (max-width: 1920px){
    .grid-container{
        display: grid;
        grid-template-columns: auto auto auto auto;
        grid-gap: 3px 3px;
    }
    
    .grid-item-1{
        height: 100px;
        background-color: #F5C6D6;
        grid-column: 1/5;
    }
    .grid-item-2{
        height: 100px;
        background-color: #EE2E84;
    }
    .grid-item-3{
        height: 100px;
        background-color: #85CFD8;
        grid-column: 1/3;
    }
    .grid-item-4{
        height: 100px;
        background-color: #85CFD8;
        grid-column: 3/5;
    }
    .grid-item-5{
        height: 100px;
        background-color: #8DC63F;
        grid-column: 1/4;
    }
    .grid-item-6{
        height: 100px;
        background-color: #E76E34;
    }
}

@media only screen and (max-width: 768px){
    .grid-container{
        display: grid;
        grid-template-columns: 100%;
        grid-gap: 3px 3px;
    }
    .grid-item-1{
        height: 100px;
        background-color: #F5C6D6;
        grid-column: 1/2;
    }
    .grid-item-2{
        height: 100px;
        background-color: #EE2E84;
        grid-column: 1/2;
    }
    .grid-item-3{
        height: 100px;
        background-color: #85CFD8;
        grid-column: 1/2;
    }
    .grid-item-4{
        height: 100px;
        background-color: #85CFD8;
        grid-column: 1/2;
    }
    .grid-item-5{
        height: 100px;
        background-color: #8DC63F;
        grid-column: 1/2;
    }
    .grid-item-6{
        height: 100px;
        background-color: #E76E34;
        grid-column: 1/2;
    }
}

https://i.stack.imgur.com/2PTA4.png

https://i.stack.imgur.com/3dHm0.png

https://i.stack.imgur.com/uRG9m.png

Answer №1

It seems like the issue may be due to missing the meta tag -

Please ensure to add -

<meta name="viewport" content="width=device-width, initial-scale=1.0">

Make sure to place this within the head tags.

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

Display or conceal nested divs within ng-repeat loop

I set up a div with sub divs to establish a nested grid system. There are three levels altogether: MainDiv - Always Visible SecondDiv - Display or conceal when MainDiv is clicked on ThirdDiv - Display or conceal when SecondDiv is clicked on <div c ...

What is the best way to incorporate a range of details into a div using only jQuery, all while avoiding the use of data-

I'm struggling to find a concise way to explain this, so please bear with me. The information I'm sharing here is all just for example purposes and may sound strange. I have been working on creating a character select page where clicking on a cha ...

What methods do publications use to manage HTML5 banner advertisements?

We are working on creating animated ads with 4 distinct frames for online magazines. The magazines have strict size limits - one is 40k and the other is 50k. However, when I made an animated GIF in Photoshop under the size limit, the image quality suffered ...

Is it possible to detect inline elements that have been wrapped?

I am facing a challenge with displaying an indefinite amount of in-line elements. Depending on the width of the browser, some elements may shift to a new line. I am curious to know if it is possible to identify and isolate these rows of elements, or if the ...

Moving the element from the right side

Is there a way to change the direction of this element's transition from left to right, so that it transitions from right to left smoothly without any gaps between the element and the edge of the page? @keyframes slideInFromRight { 0% { trans ...

Anchor positioning within Firefox Mobile (for Android)

I created a homepage with multiple sections, each linked to from the main menu: <body> <header> <!-- nav used on all pages --> <a href="#nav" class="toggle-nav"> menu <i class="fa fa-bars">< ...

Increase the Step Size of an HTML Number Input by Holding Down the Time

Is there a way to implement increasing increment/step size for number inputs in HTML based on how long the user holds the stepper arrows? For instance, starting at step size=1 and gradually ramping up to larger increments like 5, 10, 20, etc. after holdin ...

The integration of HTML and CSS using ng-bind-html appears to be malfunctioning

<ion-item ng-bind-html="renderHtml(word[key])"> </ion-item> When referring to word[key], it represents: <ul> <li>item 1</li> <li>item 2</li> <li>item 3</li> </ul> This is the CSS being u ...

Iterate through three images using the `background-image` property in my Div

Is there a way to modify a code that loops through images based on an Img source in order to work with the "background-image" property of a div? HTML <div id="section2"></div> CSS #section2 { background-image: 'url(..images/banner1.jp ...

Content in a div with a transparency level set at 50%

Within a div container, I currently have text displayed. The challenge that I'm facing is that the container itself has an opacity of 0.5, and I would like the text to be fully visible with an opacity of 1. Unfortunately, due to the constraints of th ...

Tips for enabling scrolling on mobile devices

Hello there, I'm facing an issue with scrolling on my website when viewed on mobile devices. Even though I have set the div height to 100%, it appears as 'auto' on mobile screens. As a result, when the text exceeds the screen height, it bec ...

`Nginx with a touch of material design`

Currently, I'm in the process of implementing material design UI on a functioning web application. The application utilizes Nginx, PHP, and PostgreSQL. While I have proficiency in PHP and PostgreSQL to ensure the functionality (code composed in notepa ...

How can I prevent CSS styles from affecting all the tables on my website?

One issue I'm facing is that the CSS code intended for one table is affecting all the other tables on my website. Here is an example of the CSS code: tr:last-child td:last-child { border-bottom-right-radius:3px; } /*effects map*/ td { background: ...

Is there a way to retrieve the ID from a span and convert it into a string format?

let wordSpan = '<span class="we w_o_r_d_s" id="we" contenteditable="false">we</span>' console.log(wordSpan.id); console.log(wordSpan.attr('id')); console.log(wordSpan.getAttribute('id')); let newDiv = document.c ...

Learn how to create a half and half color scheme in an HTML table

I have created an HTML table that resembles a calendar. Various events are registered in the calendar, each distinguished by its color. However, I am looking to change the colors of the cells to be half and half. The image I desire is similar to this: C ...

The inclusion of a content editable feature within a carousel is leading to unexpected event propagation

I am dynamically creating an editable div using the code snippet below. <div class='reflection-field' contenteditable="true" data-number="${index}"></div> Expected Outcome: When I click on the generated div, I anticipate that the c ...

issue arising where the table's border is not displaying

I'm confused about why the border of the first tbody tr's td is not visible. https://i.stack.imgur.com/Fwlv7.png I can't see any reason why the border is not showing up. Here's what I've figured out: If the natural height of th ...

What could be causing my insertRow function to inject empty cells into my table?

I am facing an issue with adding the results of a fetch request into a table as a new row. Strangely, when I click the button to trigger this function for the first time, it adds an empty row instead of the desired data. However, on subsequent clicks, the ...

What is the best way to navigate users to a different page when they click on a button?

I recently designed a button in Dreamweaver software. Could you please guide me on how to set up the button so that when clicked, it redirects the user to a different page using Dreamweaver? Below is the HTML code for the button: <input type="submit" ...

Adding an automatically generated link within an HTML form

I am working on a web page that displays dynamic content and includes a form for user submissions. How can I add a unique reference to each of these pages within the form? <div class="detalle-form-wrap"> <div> <h1> ...