简体   繁体   English

如何制作Chrome / Opera特定的样式表?

[英]How to do a Chrome/Opera specific stylesheet?

I need to do chrome/opera hacks because of a font replacement script wanted by the client that breaks things... this is sad but everything is working in IE6-7, FF2-3 and Safari. 我需要做chrome / opera hacks,因为客户想要的字体替换脚本会破坏事情......这很难过,但一切都在IE6-7,FF2-3和Safari中工作。 I have no way of fixing the script itself, I can only hack around it using CSS and HTML. 我无法修复脚本本身,我只能使用CSS和HTML来破解它。

I'm trying to do something in the lines of : 我正在努力做一些事情:

<!--[if IE 6]>
   <link rel="stylesheet" href="ie6.css" type="text/css" media="screen" />
<![endif]-->

Is it possible? 可能吗?

I saw this way of doing chrome specific fixes like: 我看到了这种做铬特定修复的方法,如:

body:nth-of-type(1) .elementOrClassName
{
/* properties go here */
}

Is this working? 这管用吗? Is there a simpler way? 有更简单的方法吗? What about Opera? 歌剧怎么样?

Thanks! 谢谢!

A clean javascript way to do this: http://rafael.adm.br/css_browser_selector/ 一个干净的JavaScript方式: http//rafael.adm.br/css_browser_selector/

It ads browser specific classes to the body tag of your html which you can use in your css like: 它将浏览器特定的类广告到你的html的body标签,你可以在你的css中使用它:

.opera #thingie, .chrome #thingie {
  do: this;
}

Hope this helps. 希望这可以帮助。

Avoid CSS hacks. 避免CSS黑客攻击。 They will break. 他们会打破。

Google Chrome: 谷歌浏览器:

@media not all and (-webkit-min-device-pixel-ratio:0)
{  
    #example
    {
        width: 200px;
    }
}

Safari: 苹果浏览器:

@media screen and (-webkit-min-device-pixel-ratio:0)
{
    #example
    {
        width: 200px;
    }
}

Opera: 歌剧:

@media not screen and (1)
{
    #example
    {
        width: 200px;
    }
}

Make CSS apply only for Opera 11? CSS只适用于Opera 11吗?

How to make CSS visible only for Opera 如何使CSS仅对Opera可见

Future proof CSS hack for LTE Opera 10 针对LTE Opera 10的未来证明CSS攻击

for Google (and Safari) you can simply use the following; 对于Google(和Safari),您只需使用以下内容即可;

<link rel="stylesheet" href="style-sheet_chrome.css" type="text/chrome/safari" />

this will load a webkit specific style-sheet. 这将加载webkit特定的样式表。 The 'type' can be named whatever you want but has to be included. 'type'可以根据需要命名,但必须包含在内。

You just go ahead and create your stylesheet as you please and all non-webkit browsers will simply ignore it. 您可以随意创建样式表,所有非webkit浏览器都会忽略它。

You'll have to use the hacks above for the Opera. 你将不得不使用上面的黑客为Opera。 The following worked best for me: 以下对我来说效果最好:

@media not screen and (1)
    {
    #example
    {
    width: 200px;
    }
}

I've used it to load browser-specific @font-face declarations. 我用它来加载特定于浏览器的@ font-face声明。

I haven't tested this solution, but according to this blog entry , you could try the following for Chrome: 我没有测试过此解决方案,但根据此博客条目 ,您可以针对Chrome尝试以下操作:

if (navigator.userAgent.toLowerCase().indexOf('chrome') > -1)
{
     var chromeCss = document.createElement("link");

     chromeCss.rel = "stylesheet";
     chromeCss.href = "ChromeStyle.css";

     document.getElementsByTagName("head")[0].appendChild(chromeCss);
}

.ie - Internet Explorer (All versions) .ie - Internet Explorer(所有版本)
.ie10 - Internet Explorer 10.x .ie10 - Internet Explorer 10.x.
.ie9 - Internet Explorer 9.x .ie9 - Internet Explorer 9.x.
.ie8 - Internet Explorer 8.x .ie8 - Internet Explorer 8.x.
.ie7 - Internet Explorer 7.x .ie7 - Internet Explorer 7.x.
.ie6 - Internet Explorer 6.x .ie6 - Internet Explorer 6.x.
.ie5 - Internet Explorer 5.x .ie5 - Internet Explorer 5.x.
.gecko - Firefox (all versions), Camino, SeaMonkey .gecko - Firefox(所有版本),Camino,SeaMonkey
.ffxx - Firefox xx (change xx with number of specific version) new .ffxx - Firefox xx(用特定版本号更改xx)新
.ff4 - Firefox 4.x .ff4 - Firefox 4.x.
.ff3 - Firefox 3.x .ff3 - Firefox 3.x.
.ff2 - Firefox 2.x .ff2 - Firefox 2.x.
.opera - Opera (All versions) .opera - Opera(所有版本)
.opera12 - Opera 12.x .opera12 - Opera 12.x.
.opera11 - Opera 11.x .opera11 - Opera 11.x.
.opera10 - Opera 10.x .opera10 - Opera 10.x.
.opera9 - Opera 9.x .opera9 - Opera 9.x.
.opera8 - Opera 8.x .opera8 - Opera 8.x.
.konqueror - Konqueror .konqueror - Konqueror
.webkit - Safari, NetNewsWire, OmniWeb, Shiira, Google Chrome .webkit - Safari,NetNewsWire,OmniWeb,Shiira,谷歌Chrome
.chrome - Google Chrome (All versions) .chrome - 谷歌浏览器(所有版本)
.chromexx - Chrome xx (change xx with number of specific version) new .chromexx - Chrome xx(更改xx与特定版本号)新增
.safari - Safari (All versions) new .safari - Safari(所有版本)全新
.iron - SRWare Iron .iron - SRWare Iron

.[OS code].[Browser code] .yourclass { padding-left:5px; 。[OS代码]。[浏览器代码] .yourclass {padding-left:5px; font-size:14px } font-size:14px}

body { background-color:#000 } body {background-color:#000}
.ie8 body {background-color:#111 } (Specific for Internet Explorer 8.x) .ie8 body {background-color:#111}(特定于Internet Explorer 8.x)
.win.ie8 body { background-color:#222 } (Specific for Internet Explorer 8.x, on Microsoft Windows all versions) .win.ie8 body {background-color:#222}(特定于Internet Explorer 8.x,在Microsoft Windows上所有版本)
.opera body { background-color:#333 } (Opera all versions) .opera body {background-color:#333}(Opera所有版本)
.ff15 body { background-color:#444 } (Specific for Firefox 15.x) .ff15 body {background-color:#444}(特定于Firefox 15.x)
.linux.gecko body { background-color:#555 } (Firefox, Camino, SeaMonkey all versions, on x11 and Linux ) .linux.gecko body {background-color:#555}(Firefox,Camino,SeaMonkey所有版本,x11和Linux)

.ie7 #right, .ie7 #left { width:320px } .ie7 #right,.ie7 #left {width:320px}

For more information visit this link http://cssbs.altervista.org/ 欲了解更多信息,请访问此链接http://cssbs.altervista.org/

Just remember that : "User-Agent sniffing is baaaddd" 请记住:“用户代理嗅探是baaaddd”

That's not and will never be a good practice. 那不是也不会是一个好习惯。

It's just pain in the ass to maintain a website where User-Agent sniffing is implemented. 维护一个实现User-Agent嗅探的网站真是太痛苦了。

You should prefer separated stylesheets, or css hacks if they're in low quantity or if you don't have time to make multiple stylesheets. 如果数量少或者没有时间制作多个样式表,您应该更喜欢单独的样式表或css hacks。

For Opera you can use this trick : 对于Opera,你可以使用这个技巧:

@media all and (-webkit-min-device-pixel-ratio:10000),
    not all and (-webkit-min-device-pixel-ratio:0) { 
     #id {
         css rule;
     }
 }

And Sadly, every Chrome css hacks are also applyed to Safari. 可悲的是,每个Chrome css hacks也适用于Safari。

There's no way to separate the 2 renderings excepted for the old versions of Safari (<= safari3 if I remember well) 除了旧版本的Safari之外,没有办法将2个渲染区分开(如果我记得很清楚的话,<= safari3)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM