【问题标题】:Media queries not working in specific IE query媒体查询在特定 IE 查询中不起作用
【发布时间】:2019-11-03 04:17:14
【问题描述】:

我正在尝试仅在一个浏览器 (IE) 中使用媒体查询,但我尝试过的都没有。

例如:

@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {
    /* Styles go here for IE */
    @media screen and (max-width: 700px) {
        .article {
            width: 100%!important;
        }
    }
 }

我正在尝试让媒体查询仅适用于 IE,而不适用于其他任何东西,但这没有任何影响。我也试过:

@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none), (max-width: 1320px) {
    div#desktop-nav {
        padding-left: 0px!important;
        padding-right: 0px!important;
    }
}

我将最大宽度添加到媒体查询的末尾。

如果有人知道如何针对特定浏览器进行媒体查询,请告诉我

【问题讨论】:

  • 您需要提供一个minimal reproducible example,这样我们才能看到它实际上不起作用。
  • 另外,您要定位哪些 IE 版本?

标签: html css internet-explorer media-queries


【解决方案1】:

您似乎正在尝试以 IE 10+ 为目标,因此请尝试使用 all 选择器而不是 screen 选择器。

@media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
   /* IE10+ CSS */
}

如果您尝试以 IE 9 或更低版本为目标,则必须加载条件样式表,如下所示:

<!--[if IE]>
   <link rel="stylesheet" type="text/css" href="ie.css" />
<![endif]-->

您可以在此处找到有关此浏览器和其他 Microsoft 浏览器的更多详细信息:

how to detect IE and Edge browsers in CSS?

【讨论】:

    【解决方案2】:

    您使用逗号而不是 and 关键字分隔条件

    @media screen and (-ms-high-contrast: active) and (-ms-high-contrast: none) and (max-width: 1320px) {
        div#desktop-nav {
            padding-left: 0px!important;
            padding-right: 0px!important;
        }
    }
    

    【讨论】:

    • 我刚刚试了一下,似乎并没有改变结果。
    • 是的,它只在 IE 中进行更改,但只是媒体查询不起作用。
    • 不幸的是,我在 mac 上在实际的 IE 上进行测试,对不起
    猜你喜欢
    • 2015-02-02
    • 2016-04-04
    • 2011-10-18
    • 2013-12-31
    • 2014-02-21
    • 1970-01-01
    相关资源
    最近更新 更多