How do I add a css line ONLY for Safari

后端 未结 7 1527
轮回少年
轮回少年 2020-12-28 11:03

I am making a website, but an element needs margin in Chrome and other browsers, but not in safari. So I want to add a css line to fix it, but I can\'t find any method to ad

7条回答
  •  北海茫月
    2020-12-28 11:21

    I believe this should work

    Fiddle : http://jsfiddle.net/kHFjM/1/

        var userAgent = navigator.userAgent.toLowerCase(); 
        if (userAgent .indexOf('safari')!=-1){ 
           if(userAgent .indexOf('chrome')  > -1){
             //browser is chrome
           }else if((userAgent .indexOf('opera')  > -1)||(userAgent .indexOf('opr')  > -1)){
             //browser is opera 
           }else{
            //browser is safari, add css
           }
        }
    

    here is the link to detect the browser version https://stackoverflow.com/a/5918791

提交回复
热议问题