更改依赖于浏览器的类中的元素

Change an element in a class dependant on browser

本文关键字:元素 浏览器 依赖于      更新时间:2023-09-26

我想要的是检测用户是否使用chrome,然后改变该类的margin-bottom,以不同的东西?

这是div:

<div id="titleAreaBox" class="ms-noList ms-table">

这是我使用的类:

#titleAreaBox{
    margin-left:0px;
    height:0px; 
    margin-bottom:-31px;    
}

所以我想能够改变这个类的margin-bottom:-31px元素,如果浏览器是chrome....这在javascript中可能吗?

var isChrome = navigator.userAgent.toLowerCase().indexOf('chrome') >= 0;
if(isChrome) document.getElementById('titleAreaBox').style.marginBottom = '-31px';

我会调查一下http://www.quirksmode.org/js/detect.html

这是一段很长的代码,但它似乎涵盖了所有的浏览器,你可以复制并粘贴它