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

Blurring the edges of a div container

I have successfully faded the top of a div, but I am struggling to achieve the same effect for the bottom. I attempted to reverse the CSS properties used for fading the top, but it does not seem to be working as expected. HTML: <div class="container-c ...

Is there a way for me to position my menu on the right side of my website?

I am currently working on a gallery website and facing an issue with the menu placement. I want to position the menu items on the right side of the images, but they keep appearing at the bottom instead. Despite adjusting the width in classes like galleryme ...

Transition from Material UI styles to SCSS equivalent

Can you assist me in converting the following Material UI themes to its equivalent SCSS? I am defining up("sm") as meaning above600px. I'm in the process of creating a @mixin contentShiftContainer so that I can use it wherever needed. Howev ...

Tips for effectively making REST requests from a ReactJS + Redux application?

I'm currently working on a project using ReactJS and Redux, incorporating Express and Webpack as well. I have successfully set up an API and now need to figure out how to perform CRUD operations (GET, POST, PUT, DELETE) from the client-side. Could so ...

Placing the error message for validation in its appropriate position

My login form has a layout that looks like this: https://i.stack.imgur.com/i7rCj.png If I enter incorrect information, it displays like this: https://i.stack.imgur.com/ItNJn.png The issue is that when the error message appears, it causes the login form ...

javascript basic image carousel

How can I modify my slider so that "slide 1" appears after "slide 3" without needing to use the return or previous button each time? I'm not very well-versed in javascript, so I thought I'd reach out for some assistance ...

Body Zoom Browser

My website features buttons for zooming in and out, labeled as A + and A-. I wanted to make sure that the entire body of the website could be magnified easily. That's why I came up with this code: <html> <body> <style> .cont ...

Is there a way to retrieve the immediate children of all elements using CSS selectors in Selenium?

Although I attempted to utilize the ">" syntax, selenium does not seem to accept it. I am aware that Xpath can be used to obtain what I need, however our project exclusively utilizes CSS selectors. My goal is to create a list containing only the immedi ...

Determine the placement of a <div> based on information stored in localStorage

I'm diving into the world of localStorage and trying to figure out how it works. To get a better understanding, I decided to create an HTML page that allows users to drag and drop tiles around the screen. Here's a snippet of the code I came up ...

When attempting to showcase an image within an Angular form, the error message "Form control with unspecified name attribute lacks a value accessor" is displayed

I have a scenario where I am overlaying icons on an image within my ngForm. The goal is to allow users to drag the icons and save their new location when the form is submitted. Everything works as expected, but I encounter a pesky error whenever the page l ...

What is the most efficient way to load a PHP page once the webpage has completely finished loading?

I'm relatively inexperienced when it comes to PHP and JQuery, so please bear with me if my knowledge is limited. Currently, I'm facing an issue where loading a small HTML table that contains information queried from game servers (like shown in t ...

The embedded iframe on YouTube is displaying the incorrect video

I am currently designing a website and I want to feature a video on the homepage. The video is hosted on YouTube and I need to embed it into my website. <html> <iframe width="560" height="315" src="https://www.youtube.com/embed/spPdelVEs_k?rel= ...

The paragraph element is refusing to align with the next paragraph element on the following line

The issue I'm facing is that the paragraph element is not displaying on a separate line from the other paragraph element. body { margin: 0; padding: 0; display: flex; justify-content: center; align-items: center; height: 100vh; backgr ...

What is the best way to ensure the main container fills the entire screen?

Given: Bootstrap 5.1 Visual Studio 2022 Professional Edition Blazor Server Application How do I modify the container to occupy the entire screen without any margins? <div class="container bg-primary"> Hello World! </div> Thi ...

Setting the dimensions of an HTML - CSS block

I am trying to style a navigation bar using the following CSS code: #nav {} #nav a { position: relative; display: inline-block; color: #F0F0F0; width: 1em; height: 2em; line-height: 0.9em; } #nav a.ic ...

Mootools tweening color transition denied for child elements when color is explicitly defined in CSS

Check out this link for testing: http://jsfiddle.net/EnJSM/ You might observe that by removing "color: #6CB5FF;", the transition behaves differently - it only works for the second part of the line. I'm interested to see what solution you come up wit ...

Ways to eliminate excessive spacing between grid blocks

Hey, I'm having an issue with displaying ads in a thumbnail format; there seems to be too much space between them. Take a look: I've been utilizing Bootstrap thumbnails to showcase products. echo '<div class="col-sm-6 co ...

The Photoswipe default user interface cannot be located

While attempting to incorporate PhotoSwipe into my website, I encountered an uncaught reference error related to The PhotoswipeUI_Default is not defined at the openPhotoSwipe function Below is the code snippet that I have been working on: <!doctyp ...

Having trouble with the toggle button on the Bootstrap 5 navbar?

I am facing an issue with my HTML code where the toggle button does not display properly when I resize the browser screen. Upon clicking on it, the navigation bar items do not show at all. Here is a screenshot of my website <html> <head> ...

Can Microsoft Bot Framework chat window support rounded border corners?

Is it possible to style border corners in the Microsoft bot framework? I've attempted the following: const styleSet = window.WebChat.createStyleSet({ botAvatarImage: '/assets/logo.png', bubbleBackground: ...