2013-11-20 30 views
0

對於我的生活,我無法得到爲什麼這個徽標不居中。請幫忙!無法獲取徽標到中心

<div id="header" style="width:100%;" > 
<a href="index.html"><img id="logo" src="images/logo384x80.png"/></a></div> 

和CSS

#header { 
background-color:#222222; 
height:50px; 
margin-left:auto; 
margin-right:auto; 

} 

回答

0

您可以嘗試使用文本對齊:中心風格的股利。我更喜歡使用類,並使用CSS中的類爲元素添加樣式。所以我會做這樣的事情,添加一個類來劃分東西,如:「logo」並設置下面的CSS:

.logo { background-color:#222222; height:50px; margin:auto; text-align:center; }

或您的情況:

的#header { 背景顏色:#222222; height:50px; margin:auto text-align:center; }

0

如果你給寬度爲「值」,而不是一個不存在的物體的百分比,即沒有什麼圍繞因此它的100寬度它的工作原理%意味着什麼。

改變它可以說,20em,你會看到其中的差別:

<div id="header" > 
<a href="index.html"><img id="logo" src="http://www.beyondsecurity.com/assets/img/beyond-security-logo.png"/></a></div> 

#header { 
background-color:#222222; 
width: 20em; 
height: 50px; 
margin-left:auto; 
margin-right:auto; 
} 
+0

謝謝你們倆。庫什的答案是合適的。 – Sash