Css 表达式在 IE11 中不起作用

Css Expression not working in IE11

我们使用旧版本的 IE7 开发了一个应用程序。

并且代码包含 "CSS expression" 但这在 IE11 中不起作用。

示例代码:

div#GridViewContainer
        {
            position: relative !important;
            width: 1000px !important;
            overflow: auto !important;
        }
        _:-ms-fullscreen, :root .staticHeader
        {
            position: relative !important;
            top: expression(this.offsetParent.scrollTop);
            z-index: 99 !important;
        }
        _:-ms-fullscreen, :root .StaticColumn
        {
            z-index: 90 !important;
            border: 1px solid gray !important;
            position: relative !important;
           left: expression(document.getElementById("GridViewContainer").scrollLeft);
        }

如何在 IE11 中工作以及其他方法?

如何修改我的代码?

  • 如果你懒惰或者不想用JS,试试设置Document模式:

    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
    

    将其添加到 <head>...</head> 部分。

    请注意,这可能会破坏您可能使用过的 IE7 不支持的属性。


为什么要避免使用 CSS 表达式:

Starting with Internet Explorer 11, CSS expressions are no longer enabled for webpages loaded in the Internet zone. CSS expressions are supported for pages loaded in other zones (such as the intranet zone) when pages are rendered in IE7 standards mode or IE5 quirks mode.

-CSS expressions no longer supported for the Internet zone

此外,

Unfortunately, the performance penalty imposed by CSS expressions is considerable, as the browser reevaluates each expression whenever any event is triggered, such as a window resize, a mouse movement and so on. The poor performance of CSS expressions is one of the reasons they are now deprecated in IE 8. If you have used CSS expressions in your pages, you should make every effort to remove them and use other methods to achieve the same functionality

-Page Speed: Avoid CSS expressions (deprecated)

条件注释应该像 Leo Caseiroin 在他的回答中所建议的那样起作用,它实际上会在 IE7+ 上为您节省一些带宽。

我建议你用你的 hacks 拆分你的文件,然后你可以使用 IE 的条件注释,如下所示:

<link href="css/ie11-without-hacks.css" rel="stylesheet">
<!--[if lt IE 7]>
    <link href="css/ie7hacks.css" rel="stylesheet">
<![endif]-->

关于条件注释: https://msdn.microsoft.com/en-us/library/ms537512(v=vs.85).aspx