Are you looking for a solution to address nested media queries in Internet Explorer?

My HTML and CSS code is looking fantastic and responsive on all browsers except for IE (specifically tested in IE11). It seems that IE is not interpreting the padding correctly, causing an issue with text placement. To address this problem, I decided to utilize a media query:

@media only screen and (max-width: 1200px) {

    /* some css stuff */

    @media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {

        /* Implementing specific CSS for IE within a max-width of 1200px */
    }
}

This approach effectively targets the browser; however, it has introduced a new challenge. Since I am making the site responsive without using Bootstrap or any other framework, I rely heavily on media queries. Unfortunately, IE does not support nested media queries.

As a result, my design is no longer as responsive as intended. Are there any alternative solutions or workarounds that I may have overlooked?

Answer №1

Rework your @media queries to eliminate nesting - although this may require duplicating some rules (consider utilizing tools like Sass or T4 if you favor Visual Studio).

Original Structure:

@media only screen and (max-width: 1200px) {

    .rule1 {
        color: black;
    }

    .rule2 {
        color: red;
    }

    @media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {

        /* CSS specific to IE within a max-width of 1200px */
        .ieRule1 {
            color: blue;
        }
    }
}

Revised Approach:

@media only screen and (max-width: 1200px) {

    .rule1 {
        color: black;
    }

    .rule2 {
        color: red;
    }
}

@media all and (max-width: 1200px) and (-ms-high-contrast: none), (-ms-high-contrast: active) {

    .rule1 {
        color: black;
    }

    .rule2 {
        color: red;
    }

    .ieRule1 {
        color: blue;
    }
}

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

Incorporating the <sub> element while maintaining the line height

I am facing a challenge with formatting text that includes subscripts and superscripts tags. For example: <div>hello <sub>world</sub>, how are you? Translated as logical aggregates or associative compounds, these characters have been int ...

Initiate playing YouTube videos by clicking on an image using HTML and CSS

Currently, I am in the process of learning HTML, CSS, and CSS3. I am trying to figure out how to play YouTube videos by clicking on an image using only HTML and CSS or CSS3. If anyone has any suggestions or guidance on how to achieve this, please let me ...

Angular Components unexpectedly lose background transparency when using Transparent-Background-PNG in the foreground

Hey there! I'm currently working on a landing page and I have this amazing idea to use a stunning picture of clouds with a transparent background layered over a beautiful landscape. The only problem is that when I try to implement it, the transparency ...

Using jQuery to transform HTML data attributes into an array

I have a set of stacks, each containing an h1, h2, and some paragraph text. Each element within the stack has a data-style attribute with the font family name as its value. For example: <h1 data-style="arial">Heading 1</h1> My goal is to use ...

Revamping the Look: Refreshing Background of Div

I'm attempting to change the background image of the body element on a webpage when I hover over links with data-* attributes. It's working perfectly, but I can't seem to figure out how to create a smooth fade between the images when a link ...

What is the best way to ensure that my divs adjust to fit the remaining space, irrespective of the number I create

I'm working on creating an etch-a-sketch in the browser. Right now, it only works with a size of 7200, but I want to make it more dynamic. I'd like users to be able to input any number and have the grid adjust accordingly. For example, if they en ...

ErrorType at /create Listing() received an unexpected argument: 'description'

I'm having trouble with my ecommerce site as it's not allowing me to create listings and post them. Below is the code from my views.py: ... (insert code snippet here) ... Here is the excerpt from my models.py: ... (insert code snippet here) . ...

Having trouble retrieving the text of an element using Selenium

Looking at the DOM element provided: <span class="styles__Content-rlm06o-1 ixoRjG">20.00000000</span> I am attempting to extract the value 20.00000000 using the following Python code: text = driver.find_elements_by_xpath("//*[@c ...

What is the best way to calculate the width of an element that exceeds its container using javascript?

I am looking to create a WordPress plugin that can detect if any title exceeds its designated container and adjust the font size accordingly. The PHP script I have written iterates through all titles on each page and post, extracting each word and storing ...

I attempted to update the text on an HTML page using the content of "conetnt", however, it was unsuccessful

.custom-div { outline: none !important; width: 450px; margin: auto; background-color: #ccc !important; text-indent: -9999px;} .custom-div::before{content: 'sample';color: black;} ...

Can CSS selectors be grouped together under the same root?

Is it possible to cluster these selectors together in normal CSS like below? .container { .header {...} .content p {...} .button-wrapper .button {...} .footer {...} } Or do I need to use Sass in order to achieve this grouping? ...

Discover more about the Magento module/script by reading further

I recently integrated a module into my Magento website to manage the read more or less functionality as discussed in this post: How to add jquery readmore function (expand/collapse) to magento CMS pages However, I am currently experiencing two issues: ...

Enhancing the visual appeal of HTML code in "view Source" by injecting it using a System.Web.UI.WebControls.Literal

I am currently placing code within a literal in the following manner. ImageItem.Text = string.Format("<div class=\"thumb\"><img src=\"{0}\" width=\"132\" height=\"99\" /><a class=\"more\"> ...

My website displays perfectly on both iPhone 4 and iPhone 4S

In my mobile web application, I create graphics using CSS3/HTML5. While the graphics look great on iPhone3G and iPhone3GS due to their similar pixel ratio, they appear exactly the same on iPhone4 and iPhone4S despite the better pixel ratio of the latter. ...

Adjust the minimum height and width when resizing the window

Apologies in advance if this has already been addressed, but I have tried solutions from other sources without success. My Objective: I aim to set the minimum height and width of a div based on the current dimensions of the document. This should trigger ...

Ensure that the icon at the conclusion of the <p> tag remains intact and does not break off on its

Issue at hand: The clock icons on my phone screen sometimes break off, see example here: https://i.sstatic.net/NQz9i.png Preferred outcome: The icons should be intact along with the time value, like this: https://i.sstatic.net/nZmC9.png Here is the H ...

Learn how to capture a WebSocket connection at 'ws://' that was not successful: Error encountered during connection establishment: net::ERR_CONNECTION_REFUSED

I'm currently working with basic HTML5 web sockets. Everything works perfectly fine when the server is running, but I encountered an issue when I tried closing the server for testing purposes. The error message that I receive is: WebSocket connection ...

What is the reason for making the position of bg-container absolute?

Discover more about the "position: absolute" attribute Remove the position property for troubleshooting After testing this page in Chrome, I encountered a confusion regarding the usage of the position property within the bg-container. To my surprise, del ...

The code is malfunctioning on this site (yet functions perfectly on a different website)

So I have a question that may seem silly, but it's worth asking. I'm attempting to create a sticky div element that stays in place when you scroll past a certain point on the page. This is the script I have: <script type="text/javascript"> ...

Eliminate screen flickering during initial page load

I've been developing a static website using NuxtJS where users can choose between dark mode and default CSS media query selectors. Here is the code snippet for achieving this: <template> <div class="container"> <vertical-nav /> ...