仅对 Safari 应用 CSS?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4053930/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 23:04:23  来源:igfitidea点击:

Apply CSS only for Safari?

csssafari

提问by Zach Smith

Is it possible to add a block of css that I only want to be displayed in Safari and no other browsers?

是否可以添加我只想在 Safari 中显示而不在其他浏览器中显示的 css 块?

回答by Brian Scott

Here's an example which would set the font colour of your site to green if your browser is Safari or Chrome (both share the common Webkit rendering engine).

这是一个示例,如果您的浏览器是 Safari 或 Chrome(两者共享通用的 Webkit 渲染引擎),则该示例会将您网站的字体颜色设置为绿色。

@media screen and (-webkit-min-device-pixel-ratio:0) {
    body {
        color:green; /* on Safari and Chrome  */
    }
}

This is taken from another post here

这是从这里的另一篇文章中获取的

回答by josh.trow

Using the UserAgent string, you can check for Safari and !Chrome. Both use the WebKit Renderer and both have Safari in the UA string, but Chrome also has 'Chrome'. To be honest, I'd just check for Webkit and code to that because who knows what other WebKit browser put in their UA strings.

使用 UserAgent 字符串,您可以检查 Safari 和 !Chrome。两者都使用 WebKit Renderer,并且在 UA 字符串中都有 Safari,但 Chrome 也有“Chrome”。老实说,我只是检查 Webkit 和代码,因为谁知道其他 WebKit 浏览器在他们的 UA 字符串中放入了什么。

Safari :

苹果浏览器 :

Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-HK) AppleWebKit/533.18.1 (KHTML, like Gecko) Version/5.0.2 Safari/533.18.5

Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-HK) AppleWebKit/533.18.1 (KHTML, like Gecko) Version/5.0.2 Safari/533.18.5

Chrome :

铬合金 :

Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/540.0 (KHTML, like Gecko) Ubuntu/10.10 Chrome/8.1.0.0 Safari/540.0

Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/540.0 (KHTML, like Gecko) Ubuntu/10.10 Chrome/8.1.0.0 Safari/540.0

回答by Sheo Sagar

Use this. It will work only in Safari.

用这个。它仅适用于 Safari。

/* Only for Safari  */
::i-block-chrome, .yourClassName {
     border:1px solid #f00;
}