Media queries do not trigger the execution of CSS code

I am currently working on making a desktop-sized website responsive. However, I have encountered an issue where the CSS rule is being read by the browser but not executed, regardless of whether the media query rule is true or not. I have already included

<meta content="width=device-width, initial-scale=1" name="viewport" />
, but there has been no change. I am having trouble understanding why the browser is not recognizing it.

div class="nav">
   <div class="logo"><a href="index.html">GETTI</a></div>
   <div class="nav-menu">
      <div class="menu-item"><a href="#">Home</a></div>
      <div class="menu-item"><a href="#">Why Choose Us</a></div>
      <div class="menu-item"><a href="#">How it works</a></div>
      <div class="menu-item"><a href="#">Teams</a></div>
      <div class="menu-item"><a href="#">Contacts</a></div>
    </div>

CSS:

@media screen and (max-width: 768px) {
    body {
        width:100%;
    }
    .nav-menu {
        display:none;
    }
}

I suspect that the issue may be related to how the non-responsive CSS was written, so I will also include that for reference.

.nav-menu {
    display: -ms-grid;
    display: grid;
    -ms-grid-columns: (20%)[auto-fill];
    grid-template-columns: repeat(auto-fill, 20%);
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    text-align: center;
    line-height: 100%;
}

Answer №1

When arranging your CSS rules, it is crucial to note the sequence for optimal results. For instance, if you place the media query rules before the general rules as seen in your initial question, the general rules will consistently take precedence over the media queries. This is because the general rules apply universally to all screen sizes. To ensure the desired styling effects, simply rearrange the order by placing the general rules first followed by the media queries.

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

Emphasizing the content of the text file with the inclusion of span tags

I am relatively new to working with angular js and javascript. I have a document or text file that looks something like this: Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dumm ...

Equal-height rows and columns using Flexbox

I've been working on a row layout with two columns, each set to 50% width. The left column contains an image, while the right column displays text. Here is my HTML: .row{ display:flex; ...

iOS is not recognizing the <a> tag but is instead honoring the :hover property

Within my list, I have a div element wrapped in an anchor tag. Here is an example of the code: <li> <a href="http://google.com/"> <div id="tease-info"> <div class="inset-img-border fade"></div> <img src=" ...

Problems arose when attempting to adjust the size of the container function

I've been working on a Joomla 2.5 template that consists of three main sections: top, container, and footer. While trying to set the "container" section to have a minimum height of 100%, I faced various challenges which led me to use jQuery for assist ...

Maintain parent hover effect while child is being hovered over

After exploring various solutions to fix an issue, I've hit a roadblock. Adding CSS and jQuery code seemed promising at first, but upon refreshing the browser, a new problem emerged. The parent element retained its hover state background color, but th ...

Adjust the text area to automatically expand or shrink based on the text it contains

Is there a way to automatically adjust the size of a textarea based on its content? Here is the code I am currently using for this purpose: var element = document.getElementById(event.target.id); var content = $(this).val().trim(); if (content == "") { ...

How to make a DIV element the same width as a TABLE element

Within my container DIV, there are three elements: two banner DIVs (representing a header and footer) and a wide TABLE. Despite the horizontal scrolling required for the large TABLE, I need the banner background colors to extend the full length of the DIV. ...

I am currently working on creating a timer and I am looking to position these three buttons in a circular formation

I want to create a stopwatch with 3 responsive buttons arranged in a circular layout. I have successfully built a responsive circle and now need help adding the buttons inside the circle next to the timer. To view the code, click here: https://jsfiddle.ne ...

Creating a triangular shape using a div element

Struggling to create a triangular div? I used the border trick to make it, but now there's a transparent line slicing through the triangle like a dividing line. I've attempted various solutions to make that line solid, but nothing seems to be wor ...

Customize the bootstrap carousel to show multiple slides at the same time

I am looking to customize the bootstrap 3 carousel in order to show multiple slides at once. I understand that I could place several thumbnails in a single slide (div .item), but the issue is that the carousel will progress through them all at once, moving ...

Center text with font awesome symbols

I'm looking for a way to vertically align text next to my FontAwesome icons without using manual padding. Is there a better method for achieving this? https://i.stack.imgur.com/PWwSJ.jpg <div class="row"> <div id="tb-testimonial" class="tes ...

HTML does not support the use of certain symbols

Currently, I am in the process of designing a homepage for my school project. However, I have run into an issue. The content that I want to be displayed on my homepage is as follows: "Daudzspēlētāju tiešsaites lomu spēle (Massively Multiplayer Online ...

ExpressJS encountered an error due to an unsupported MIME type ('text/html') being used as a stylesheet MIME type

Whenever I start my NodeJS server and enter localhost:8080, I encounter the mentioned error while the page is loading. The head section of my index.html file is provided below. It's puzzling to me why this error is happening, considering that my index ...

How do I use CSS to organize data by row and column within a table?

I'm looking to format the table data in a column-row layout for mobile devices. Can anyone provide an example or guidance on how to achieve this? I've browsed through some discussions but haven't found a solution that works with tables. The ...

Personalize your Native Base tab design

Recently, I've delved into the world of React Native and now find myself in need of assistance with customizing my tabs. Utilizing advanced tabs by Native Base, I aim to transform this: https://i.stack.imgur.com/xhNwP.png Into something more akin ...

I am experiencing an issue where the CSS file in the wwwroot directory does not update when I make changes to the code in ASP.NET MVC

Here is a link to my CSS file: Click here for image description This is how the file looks when built (no changes): Click here for image description Occasionally, running "clean-solution" and "build-solution" fixes the issue, but it's not working no ...

Maximizing Compatibility of CSS3 Responsive Image Sprites for Firefox

Take a look at the Demo. Make sure to test it on both Chrome and Firefox to experience the difference. I've created a div element with the following CSS classes to make a responsive sprite of images: .what-wwb-logo, .what-national-geographic-logo, . ...

Expanding the width of a bootstrap dropdown menu

Looking for advice on how to expand the dropdown width? I have a row with two columns and some JavaScript that handles the dropdown functionality. The issue I'm facing is that I can't figure out how to adjust the dropdown width when it's se ...

The functionality of changing the checkbox to "checked" by clicking on the span is not

How can I create a toggle button with a checkbox using css and jquery? Clicking on the span representing the toggle button should change the checked property of the checkbox. Currently, the span does not change the property, even though it triggers the c ...

Unique Text: "Personalized marker/pin for interactive map feature"

Looking to create a custom image map marker/pin with a unique bottom design resembling a union shape using CSS and Vue.js. I've attempted it myself but haven't been able to achieve the exact look as shown in the reference image. Any advice or ass ...