[英]How to add CSS Hack specifically for IE10?
我想為iE 10添加css。
實際上我的css在chrome和firefox中運行良好。 但是在IE 10中造成了一些問題。
我嘗試了這個代碼,並制作了ie10.css,但它無法正常工作。
<script>
if (/*@cc_on!@*/false) {
var headHTML = document.getElementsByTagName('head')[0].innerHTML;
headHTML += '<link type="text/css" rel="stylesheet" href="css/ie10.css">';
document.getElementsByTagName('head')[0].innerHTML = headHTML;
}
</script>
它不起作用。 請幫助。
您可以使用輕松跟蹤IE的最新版本(主要是IE 10和IE 11)
1. CSS媒體查詢hack:
/*
#ie10,11 will only be red in MSIE 10,
both in high contrast (display setting) and default mode
*/
@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {
//-- Put your IE specific css class here
}
要么
@media screen and (min-width:0\0) {
/* IE9 and IE10 rule sets go here */
}
2.瀏覽器檢測:
if ($.browser.msie && $.browser.version == 10) {
$("html").addClass("ie10");
}
3.使用腳本(未測試):
<script>
/*@cc_on
@if (@_jscript_version == 10)
document.write('<link type= "text/css" rel="stylesheet" href="your-ie10-styles.css" />');
@end
@*/
</script >
注意:我知道document.write
被認為是不好的做法。
條件評論(即10條條款評論):
如果要為IE加載外部css文件,可以使用條件注釋 。 但正如你提到的那樣,你想要IE 10和ie10刪除條件評論。
這是我在項目中使用的另一個技巧,你可以用你的類或自己的CSS替換h1
僅限IE10
使用此JavaScript:
var doc = document.documentElement;
doc.setAttribute('data-useragent', navigator.userAgent);
然后使用這個CSS:
html[data-useragent*='MSIE 10.0'] h1 { color: blue; }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.