栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

每个浏览器使用不同的CSS?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

每个浏览器使用不同的CSS?

您想要的理想解决方案不存在:

不幸的是,如果您尝试在HTML本身上进行操作,则不存在跨浏览器解决方案。但是,它将适用于大多数版本的IE。像这样:

<!--[if IE]><link rel="stylesheet" type="text/css" href="includes/myIEGeneralStyle.css" /><![endif]--><!--[if IE 6]><link rel="stylesheet" type="text/css" href="includes/myIE6Style.css" /><![endif]--><!--[if IE 7]><link rel="stylesheet" type="text/css" href="includes/myIE7Style.css" /><![endif]--><!--[if IE 8]><link rel="stylesheet" type="text/css" href="includes/myIE8Style.css" /><![endif]-->

所以最好的解决方案是:

这样的Javascript解决方案怎么样:浏览器检测。阅读有关此类的内容以更好地弄清该文件的基本作用,就是这样的概念:

var browser = navigator.userAgent.toLowerCase().indexOf('chrome') > -1 ? 'chrome' : 'other';

显然,它不仅可以检测浏览器的类型。实际上,它知道版本,操作系统以及您可以在该链接中阅读的更多详细信息。但是,它确实可以通过将“ chrome”替换为“
mozilla”,“ explorer”等来检查所有类型的浏览器…

然后要添加css文件,只需遵循如下条件语句即可:

if (BrowserDetect.browser.indexOf("chrome")>-1) {document.write('<'+'link rel="stylesheet" href="../component/chromeCSSStyles.css" />');} else if (BrowserDetect.browser.indexOf("mozilla")>-1) {    document.write('<'+'link rel="stylesheet" href="../component/mozillaStyles.css" />');} else if (BrowserDetect.browser.indexOf("explorer")>-1) {    document.write('<'+'link rel="stylesheet" href="../component/explorerStyles.css" />');}

祝你好运,希望这能帮到你!



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/568350.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号