2014-11-21 18 views
1

上設置頁面邊距。我嘗試在頁面加載時使用chrome中的JQuery頁邊空白進行設置。

$(window).load(function(){ 

    var isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor); 
    var isSafari = /Safari/.test(navigator.userAgent) && /Apple Computer/.test(navigator.vendor); 


    if (isChrome) { 
     //alert("You are using Chrome!"); 
     $('.footer_links').css("margin-top","0px;"); 
    } 

    if (isSafari) { 
     //alert("You are using Safari!"); 
     $('.footer_links').css("margin-top","10px;"); 
    } 

與Safari它工作良好,但鉻失敗。但是當我想更改背景顏色時,如:

$('.footer_links').css("background-color","red"); 

它同時適用於Chrome和Safari。

預先感謝您的幫助!

+2

移除;這從pxto是'0px'和'10px' – 2014-11-21 15:15:54

+1

你爲什麼要那樣做?如果(isChrome){alert(「您正在使用Chrome!」),爲什麼不用'* {box-sizing:border-box}' – 2014-11-21 15:16:19

+0

來解決相同問題的用戶 ; $('。footer_links')。css(「marginTop」,「0px;」); } – 2014-11-21 15:25:57

回答

1

使用

$('.footer_links').css("margin-top", "0"); 

,而不是

$('.footer_links').css("margin-top", "0px;"); 
0

問題是0px;

寫不px;

0
css("margin-top","0px;"); 

css("margin-top","0px"); 

css("margin-top","10px;"); 

css("margin-top","10px"); 

而不;