繁体   English   中英

添加样式 position 相对 IE 和 position 绝对其他浏览器

[英]add style position relative for IE and position absolute for other browsers

我想添加样式 position:relative for ie 和 position:absolute for other browsers

这是我的代码

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

如何解决

忽略维护问题,针对除 IE 之外的所有浏览器的技巧是使用 IE上根本不支持的@support()规则。

如果您尝试为 IE 浏览器应用特定的 styles,那么您应该尝试使用以下媒体查询来定位 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 浏览器。

参考:

如何在样式表中仅定位 IE(任何版本)?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM