簡體   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