如何只定位一个浏览器? [英] How to target only one browser?
本文介绍了如何只定位一个浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想为一个浏览器设置一个div的高度,所以它在Firefox或其他方面看起来不奇怪。
以下是一个例子:
#example {height:200px; <! - 我如何瞄准Safari? - > height:250px; <! - 如何以Firefox为例? - > height:300px; <! - 如何以IE为例? - > width:250px; background-color:#FFF;}
< div id = 例如 > < img src =example.png> < p>只是一些文字。< / p> < p>点击< a href =www.example.com>此处< / a>访问www.example.com< / p>< / div>
b
$ b
我已经尝试过 -moz-height:250px;
但它没有用。
解决方案
为此,您可以使用 JavaScript 。有一个可以访问的字符串,称为 navigator.appName
。你可以放这个:
if(navigator.appName ===Google Chrome)
// Do无论在哪里
将 Microsoft Internet Explorer 替换为您的目标浏览器。
我真的希望这有助于!
I would like to set a height for a div only for one browser, so it doesn't look weird in Firefox or whatever.
Here is an example:
#example {
height: 200px; <!--How can I target Safari for example?-->
height: 250px; <!--How can I target Firefox for example?-->
height: 300px; <!--How can I target IE for example?-->
width: 250px;
background-color: #FFF;
}
<div id="example">
<img src="example.png">
<p>Just some text.</p>
<p>Click <a href="www.example.com">here</a> to visit www.example.com</p>
</div>
I've already tried -moz-height: 250px;
but it didn't work.
解决方案
For this, you can use JavaScript. There is a string that you can access called navigator.appName
. You can just put this:
if(navigator.appName === "Google Chrome")
// Do whatever here
replacing Microsoft Internet Explorer with your target browser.
I really hope this helps!
这篇关于如何只定位一个浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文