2015-03-25 108 views
0

我有一個問題讓我的div下移我的頁面30px /爲我的div頂部添加30px的餘量。我的div使用margin auto在頁面中心對齊。位置div保證金頂部30px,但保留保證金在中心使用保證金自動?

但是,當我嘗試添加以下代碼行: margin:30px auto 0 auto;

沒有顯示上邊距?請有人告訴我我做錯了什麼?謝謝,

#content_other{ 
width:790px; 
height: auto; 
font-family: 'Arial Narrow', Tahoma, Verdana, Arial Narrow, sans-serif; 
font-size:12px; 
margin: 30px auto 0 auto; 
position:relative; 
overflow: hidden; 
padding:20px; 
background:#fff; 
border: 1px solid #999; 
-webkit-box-shadow: 0 3px 8px rgba(0, 0, 0, .25); 
-moz-box-shadow: 0 3px 8px rgba(0, 0, 0, .25); 
box-shadow: 0 3px 8px rgba(0, 0, 0, .25); 
-webkit-border-radius: 3px; 
-moz-border-radius: 3px; 
border-radius: 3px; 


} 

HTML:

<div id="content_other"> 

<html form here> 

</div> 
+0

它爲我在谷歌瀏覽器 – q0re 2015-03-25 12:34:37

+0

你的代碼是絕對沒問題:)不過,讓我知道,在瀏覽器中你得到這個問題。 – 2015-03-25 12:45:49

回答

0

沒有什麼錯與您的代碼。 看看JSFiddle。保證金被添加到頂部 如果頁面上的其他事情影響那麼你的整個頁面的CSS嘗試添加到margin-top的重要推動它,並覆蓋其他的東西,這可能是解除我用這個HTML

<div id="content_other"> 
    <form> 
     <input type="text" /> 
    </form> 
</div> 
0

該規則。

margin: 30px auto 0 auto !important; 
0

它取決於它周圍的容器,所以我們需要看完整的HTML。您可以添加內部包裝和浮起來:

<div id="content_other"> 
    <div id="float-wrap"> 
     <html form here> 
    </div> 
</div> 

#float-wrap { 
    float: left; 
    width: 100%; 
    margin-top: 30px; 
}