开发者

How to check the browser version and chanage the css

i have created an web page and it works fine in firefox,opera etc and fails in internet explorer 6 so i need to check the version of the internet开发者_开发百科 explorer and change the css code...

please help me how to do that


To target a specific version of Internet Explorer, use conditional comments. Those comments will be parsed only be the specified IE version(s).

Example from the linked quirksmode.org page:

<!--[if IE 6]>
Special instructions for IE 6 here
<![endif]-->

Another way to target browser versions is CSS hacks, but those are usually awful and decrease code readability and maintainability. If you need to target browsers other than IE, I recommend server-side detection of the browser version and serving the appropriate style sheet. A PHP example for that is here.


Conditional comments are your friends: use them


HTML

<!--[if IE 6]>
IE 6 STYLE GOES HEERE
<![endif]-->

You don't need javascript.


A radically different approach you could take is use Javascript to generate the CSS.
You can use variables, conditions, functions, closures to generate your CSS, and it is very fast.

We use this in the mobile version of our app.
To formalise it a bit, we developed a module hosted on github: http://github.com/pure/jstyle
The JSON notation ends up being very similar to the real CSS.

There are still areas for improvements but it does its job very well for us.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜