css - 如何为 IE 11 编写 CSS hack?

标签 css css-selectors internet-explorer-11

<分区>

我如何破解或编写仅适用于 IE 11 的 css?我有一个在 IE 11 中看起来很糟糕的网站。我到处搜索但还没有找到任何解决方案。

有没有css选择器?

最佳答案

使用 Microsoft 特定 CSS 规则的组合来过滤 IE11:

<!doctype html>
<html>
 <head>
  <title>IE10/11 Media Query Test</title>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <style>
    @media all and (-ms-high-contrast:none)
     {
     .foo { color: green } /* IE10 */
     *::-ms-backdrop, .foo { color: red } /* IE11 */
     }
  </style>
 </head>
 <body>
  <div class="foo">Hi There!!!</div>
 </body>
</html>

过滤器之所以起作用,是因为以下原因:

When a user agent cannot parse the selector (i.e., it is not valid CSS 2.1), it must ignore the selector and the following declaration block (if any) as well.

<!doctype html>
<html>
 <head>
  <title>IE10/11 Media Query Test</title>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <style>
    @media all and (-ms-high-contrast:none)
     {
     .foo { color: green } /* IE10 */
     *::-ms-backdrop, .foo { color: red } /* IE11 */
     }
  </style>
 </head>
 <body>
  <div class="foo">Hi There!!!</div>
 </body>
</html>

引用资料

关于css - 如何为 IE 11 编写 CSS hack?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20541306/

相关文章:

javascript - 滚动到页面底部时jQuery加载内容

html - 为什么我的不是 :visited style work in Chrome or IE?

internet-explorer-11 - 如何获取 Internet Explorer 11 更新发行说明

javascript - 表单/JavaScript 无法在 IE 11 上运行并出现错误 DOM7011

javascript - 在 html5 视频中切换音量

css - 一次使用多个特定于供应商的 CSS 选择器

html - 默认 :target with CSS

python - 如何使用 selenium 在 Twitter 登录页面中单击下一步 - Python

JavaScript localStorage 对象在 Windows 7 的 IE11 中损坏

css - 如何在CSS中使div背景颜色透明