css - 仅适用于 IE10+ 不适用于其他浏览器的 css 样式

标签 css internet-explorer

我想应用像

这样的 css 样式
 margin-left, height,width 

仅适用于IE浏览器。 我尝试了以下方法,但它也适用于其他浏览器。

    @media all and (-ms-high-contrast: none), (-ms-high-contrast: active)
      #chart
      {
         margin-top : -105px;
      }
      @media screen and (min-width:0\0)
      {
          #chart
         {
            margin-top : -105px;
         } 
      }

       @media screen/9 and (-ms-high-contrast: none), (-ms-high-contrast: 
       active)
          #chart
         {
            margin-top : -105px;
         }

请帮忙。 谢谢。

最佳答案

我已经测试了下面的代码。试一试

HTML:

<h1>try me </h1>

CSS:

html[data-useragent*='MSIE 10.0'] h1 {
  color: blue;
}

JS:

var b = document.documentElement;
b.setAttribute('data-useragent',  navigator.userAgent);
b.setAttribute('data-platform', navigator.platform );

https://css-tricks.com/ie-10-specific-styles/

IE9 或以上版本:

@media screen and (min-width:0) and (min-resolution: +72dpi) { 
      Your Code
 }

关于css - 仅适用于 IE10+ 不适用于其他浏览器的 css 样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48899825/

相关文章:

javascript - IE8 对象预期错误

vba - 无法使用 VBA 登录到我的确实帐户

javascript - Javascript在IFrame中刷新时禁用浏览器声音

javascript - 适用于 Internet Explorer 11 的 IntelliJ IDEA JavaScript 语言版本

javascript - 页面滚动显示

javascript - 响应式菜单隐藏覆盖 div 不显示 onclick

php - CSS 与 PHP 合并

javascript - 从变量分配时,分配的 css 类不起作用

javascript - 使用制表符遍历子项 (HTML)

jQuery slideUp 水平菜单 Internet Explorer 问题