2013-07-24 63 views
-1
/* HTML */ 
<header role="heading"> 
    <div class="logo"> 
     <h1><a href="/">this is the banner</a></h1> 
    </div> 
<header> 

/* CSS */ 
header 
{ 
    background-color: rgb(255, 165, 0); 
    height: 160px; 
    width: 100%; 
} 

header .logo 
{ 
    margin: 30px auto; 
    width: 980px; 
} 

所以,我希望爲.logoheader內中心,它...但它拉header 30PX從頂部。HTML5 CSS3嵌套DIV定位

我試過使header相對,但只會導致居中(30px自動)不起作用。

任何意見將不勝感激!

+0

你使用CSS重置了嗎? H1默認有自己的填充/保證金。 –

+0

是的。 H1的大小和一切。 – aserwin

回答

1

有時邊距也會影響父級,我建議採用以下方法:保持標記相同,並在容器上使用填充而不是邊距。

/* CSS */ 
header 
{ 
    background-color: rgb(255, 165, 0); 
    height: 160px; 
    width: 100%; 
    padding:30px 0px; /* Use padding here*/ 
} 

header .logo 
{ 
    margin: 0px auto; /* Instead of margin here */ 
    width: 980px; 
} 
+0

絕對!那是我在看了一秒之後才發現的......有時候,大聲問這個問題才能得到答案!謝謝。 – aserwin

+0

@aserwin你絕對正確:)很高興幫助隊友 –

0

的尷尬樣,但我看了看這個問題,一旦我的貼吧,看到答案... 我以前margin: 0 auto居中.logopadding-top: 30px使其下降。

抱歉浪費時間!也許這會幫助別人。