【问题标题】:add style position relative for IE and position absolute for other browsers为 IE 添加样式相对位置,为其他浏览器添加绝对位置
【发布时间】:2020-08-18 14:33:18
【问题描述】:

我想添加样式 position:relative 为 ie 和 position:absolute 为其他浏览器

这是我的代码

    <div id="textDiv"  style="display:none; background-color: #434343; padding: 5px 10px 5px 10px; margin-left: 10px; margin-top: 30px; position: absolute;"></div>

如何解决

【问题讨论】:

    标签: javascript html css internet-explorer styles


    【解决方案1】:

    如果您尝试为 IE 浏览器应用特定样式,那么您应该尝试使用以下媒体查询来定位 IE 浏览器。

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

    示例:

    <!doctype html>
    <html>
    <head>
    <style>
    #textDiv
    	{    
        		position:absolute;
        		color:green;
    	}
    @media all and (-ms-high-contrast: none), (-ms-high-contrast: active) {
    	#textDiv
    	{    
        		position:relative;
        		color:red;
    	}
    }
    </style>
    </head>
    <body>
        <div id="textDiv">This is text...</div>
    
    </body>
    </html>

    您会注意到媒体查询中的 CSS 代码仅适用于 IE 10 或 IE 11 浏览器。

    参考:

    How to target only IE (any version) within a stylesheet?

    【讨论】:

    【解决方案2】:

    忽略维护问题,针对除IE之外的所有浏览器的技巧是使用@support()规则is not supported at all on IE

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-13
      • 2011-02-02
      • 1970-01-01
      • 2016-05-14
      • 2011-04-25
      • 1970-01-01
      • 1970-01-01
      • 2014-10-06
      相关资源
      最近更新 更多