2014-12-05 47 views
0

CSSCSS保證金不響應的margin-top,但適用於其它邊距屬性

.title{ 
    margin-top: 200px; // does not work! 
    margin-left: 20px; 
    font-weight: bold; 
    color: $green; 
    font-size: 2.5em; 
} 

.title:hover{ 
    background-color: transparent; 
} 

.title:visited{ 
    color: $green; 
} 

軌/ html.erb

<body> 
    ..... 

    <%if current_page?(login_path) or request.path == "/signup"%> 
     <%= link_to "TITLE", "#", class: "title"%> 
     <%= yield %> 
    <% else %> 
    ..... 
</body> 

我的標題使用CSS的工作,但現在沒有。對我的標題總是堅持屏幕的頂部,不管怎麼樣。我試過margin-toppadding-top,但它拒絕下移。 然而,保證金餘額確實有效,所以我不太確定爲什麼保證金的某一方面有效,而另一方面沒有。

我在這裏做錯了什麼?如果你認爲問題沒有在上面的代碼中列出,而是在我的CSS中的其他地方列出,請讓我知道,以便我可以查看我的css的其他部分,問題可能在哪裏!下面

萬一是它定義了基本的佈局部分

/* BASIC CONFIGURATION */ 
body { 
    color: #797979; 
    background: $background; 
    font-family: 'Lato', sans-serif; 
    padding: 0px !important; 
    margin: 0px !important; 
    font-size:13px; 
} 

table{ 
    border-collapse: separate; 
    border-spacing: 10px 5px; 
} 

td{ 
    margin-right: 10px; 
} 

#main-content{ 
    font-family: 'Lato', sans-serif; 
} 

ul li { 
    list-style: none; 
} 

a, a:hover, a:focus { 
    text-decoration: none; 
    outline: none; 
} 

a:hover{ 
    background-color: inherit; 
} 
::selection { 

    background: #68dff0; 
    color: #fff; 
} 
::-moz-selection { 
    background: #68dff0; 
    color: #fff; 
} 

#container { 
    width: 100%; 
    height: 100%; 
} 

回答

2

你的問題就在這裏:

body { 
    color: #797979; 
    background: $background; 
    font-family: 'Lato', sans-serif; 
    padding: 0px !important; 
    margin: 0px !important; 
    font-size:13px; 
} 

您已經標記,你希望所有的利潤率和填充爲0並讓他們重要。如果你想覆蓋,你必須使你的元素對邊距很重要。

我會推薦避免!重要的儘可能多。通常情況下,你不需要它,除非你重寫一個提供的CSS來定義一些帶有!important的域。

+0

我從margin和padding中刪除了!important,並添加了margin-top:200px;到標題看是否有效,但不幸的是它仍然無法正常工作。如果我有!重要的,不應該保證金不工作嗎? – user3277633 2014-12-05 15:51:18

+0

最後,我通過將它包裝在一個div中並將其轉換爲div來修復它。但我相信其他人會讚賞你的建議! – user3277633 2014-12-05 16:13:29

0

您使用百分比padding-top。使用像素值,它會工作。這種情況下的百分比只有在固定高度時纔有效