Is it possible to have separate css stylesheets that are automatically loaded depending on what browser the website is being accessed from?

萝らか妹 提交于 2019-12-05 22:05:30

Since usually the problems are with IEs, there is a solution for that.
The next line, which you can put inside the head tags, will loads a specific CSS only if you use IE7

<!--[if IE 7]>
    <link rel="stylesheet" type="text/css" href="http://your.css/my.css" />
<![endif]-->

Same approach for other IEs.

DOK

Some people prefer to approach this differently by using a CSS reset file. Basically, that establishes a neutral starting point so that any CSS you apply will have the same, predictable result on all browsers.

One of the simplest versions, which will give you a general idea of the concept, is this:

* {
     padding:0;
     margin:0;
   }

There is a lot of discussion about this in the answers to this SO question.

And here is a roundup of links to various common approaches.

Edit: for testing in various browsers, check out this popular SO question , and this one.

If you use javascript you can put this code snippet inside your head tag to detect the user agent

<script type="text/javascript">
var browser={
    msie:navigator.userAgent.indexOf('MSIE') > -1 ? true : false,
    chrome:navigator.userAgent.indexOf('Chrome') > -1 ? true : false,
    opera:navigator.userAgent.indexOf('Opera') > -1 ? true : false,
    firefox:navigator.userAgent.indexOf('Firefox') > -1 ? true : false
}
if(browser.msie) document.write("<link REL='stylesheet' HREF='msie.css' TYPE='text/css'>");
if(browser.chrome) document.write("<link REL='stylesheet' HREF='chrome.css' TYPE='text/css'>");
if(browser.opera) document.write("<link REL='stylesheet' HREF='opera.css' TYPE='text/css'>");
if(browser.firefox) document.write("<link REL='stylesheet' HREF='firefox.css' TYPE='text/css'>");
</script>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!