2012-09-11 39 views
1
<div id="tagcontainer"><img id="tagimg" src="img/tri.png"/></div> 

CSS:爲什麼圖像不居中?

#tagcontainer { 
    width:100%; 
    top:0; 
    position:absolute; 
} 
    #tagimg { 
     position:relative; 
     margin:auto; 
    } 

不知道爲什麼我不能弄明白。爲什麼這個圖像不居中?

回答

0

再添加一個CSS屬性display:block;

#tagimg { 
     display:block; 
     position:relative; 
     margin:auto; 
    } 
0

要麼使#degimg塊級元素{display:inline-block; }或在父級上使用文本對齊中心...

2

因爲<img>是內聯元素。改爲在容器上使用text-align: center

0

試試這個:

#tagcontainer { 
width:100%; 
position:absolute; 
} 
#tagimg { 
width:[imagewidth]px; 
top:0; 
position:relative; 
margin:auto; 
}