[英]Having 2 css code blocks in html files how to make only one work using JS?
So we have 1 html file (required). 因此,我们有1个html文件(必需)。 In there 2 css style blocks and one JS block.
其中有2个CSS样式块和1个JS块。 how to make it possible to set to use one of the styles from JS?
如何使其能够设置为使用JS中的一种样式? (I need it to work in IE6 IE7 IE8 FF and chrome 9 =) I need to give one css for IE9 and Chrome 8 and up and another CSS for all others.
(我需要它在IE6 IE7 IE8 FF和chrome 9中起作用)我需要为IE9和Chrome 8及更高版本提供一个CSS,为所有其他提供CSS。
<style type="text/css" >
H1 {font-size: 24pt; font-family: arial}
</style>
<style type="text/css">
H1 {font-size: 15pt;}
</style>
Use conditional comments to target IE6 specifically, like this: 使用条件注释专门针对IE6,如下所示:
<!--[if IE 6]>
<style type="text/css">
H1 {font-size: 15pt;}
</style>
<![endif]-->
Or the other way around, whichever it is..but whatever's inside these comments will only apply to IE6. 或反之亦然,无论如何..但是这些注释中的内容仅适用于IE6。 No JavaScript is required for the above approach :)
上述方法不需要JavaScript :)
For an alternative way involving JS and handing chrome. 另一种涉及JS和处理chrome的方法。 (I learned this form ExtJs but I'm not sure where it originated.)
(我了解了这种形式的ExtJs,但不确定它起源于何处。)
Load a browser detection script. 加载浏览器检测脚本。 PPK's is pretty good: http://www.quirksmode.org/js/detect.html .
PPK相当不错: http : //www.quirksmode.org/js/detect.html 。
Add classes to document.body. 将类添加到document.body。
document.body.className += ' ' + BrowserDetect.browser
+ ' ' + BrowserDetect.browser + '-' + BrowserDetect.version;
Now write your css like this 现在像这样写你的CSS
H1 {
font-size: 24pt;
font-family: arial;
}
.Explorer-6 H1 {
font-size: 15pt;
}
.Chrome-9 H1 {
/* ... */
}
You could mix the OS in there too, but I'm not sure you'll ever need it. 您也可以在其中混合使用操作系统,但是我不确定您是否会需要它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.