是否可以仅定位Chrome,而不是所有Webkit支持的浏览器? [英] Is it possible to target Chrome only, not all Webkit powered browsers?

查看:100
本文介绍了是否可以仅定位Chrome,而不是所有Webkit支持的浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题有关,但不完全相同。

Vaguely related to this question, but not quite the same. I'd like to target Chrome ONLY, without targeting Safari.

我使用了以下媒体查询,但同时定位Chrome和Safari:

I used the following media query, but it targets both Chrome and Safari:

@media screen and (-webkit-min-device-pixel-ratio: 0) { 
    h1, h2 {
        font-weight: bold;
    }
}

Chrome在渲染标题元素粗体,即使我使用的字体的粗体版本不存在。 Safari ...不是这么多。因此超特异性靶向。作为参考,字体为 Cody Star

Chrome does a great job at rendering the header elements in bold even though a bold version of the font I'm using doesn't exist. Safari... not so much. Hence the super specific targeting. For reference, the font is Cody Star.

推荐答案

现在有可能适用于这个问题的浏览器特定的CSS黑客,但他们当然不被支持。

There are browser-specific CSS hacks that might work for this problem now, but they certainly aren't supported.

IMHO,最好的办法是使用JavaScript为body标记添加一个类,该类读取navigator.userAgent并使用该类(例如body.chrome)定位Chrome。

IMHO, your best bet is to add a class to the body tag using JavaScript that reads your navigator.userAgent and use that class (body.chrome for example) to target Chrome.

这篇关于是否可以仅定位Chrome,而不是所有Webkit支持的浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆