简体   繁体   English

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

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

I want to add style position:relative for ie and position:absolute for other browsers我想添加样式 position:relative for ie 和 position:absolute for other browsers

this is my code这是我的代码

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

How to solve it如何解决

Ignoring maintenance problematics, the trick to target all browser except IE is to use @support() rule which is not supported at all on IE .忽略维护问题,针对除 IE 之外的所有浏览器的技巧是使用 IE上根本不支持的@support()规则。

If you are trying to apply specific styles for the IE browser then you should try to use below media query to target the IE browser.如果您尝试为 IE 浏览器应用特定的 styles,那么您应该尝试使用以下媒体查询来定位 IE 浏览器。

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

}

example:例子:

 <: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>

You can notice that CSS code inside the media query will only apply for the IE 10 or IE 11 browser.您会注意到媒体查询中的 CSS 代码仅适用于 IE 10 或 IE 11 浏览器。

Reference:参考:

How to target only IE (any version) within a stylesheet? 如何在样式表中仅定位 IE(任何版本)?

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

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