2013-01-31 18 views
0

我把'a'標籤放在我的html中,然後添加相對位置,然後在'a'標籤中添加'img'標籤並添加絕對位置,左邊0,右邊0,頂部0,底部0,邊距自動到'img ' 標籤。如何使用html和css在ie7中將IMG標籤在水平和垂直方向居中?

此代碼不能在ie7中工作。在其他瀏覽器中,它工作正常。

我的代碼有什麼問題?

我創建的代碼如下:

HTML:

<a href="#" class="img-link-wrap"><img alt="Image 1" src="img/501.jpg"></a> 

CSS:

a.img-link-wrap { 
border: 1px solid #999; 
display: block; 
position: relative; 
height: 11em; 
width: 10em; 
text-align: center; 
} 

a.img-link-wrap img { 
position: absolute; 
top: 0; 
left: 0; 
bottom: 0; 
right: 0; 
margin: auto; 
} 

感謝你。

+0

不完全知道什麼youre試圖在這裏實現。你想讓'a'標籤比它內部的圖片更高更寬,然後讓它在'a'標籤內水平和垂直居中? –

回答

0

的風格,以中心的元素,使用下面的代碼片段:

.centered { 
    position: based on your choice; 
    top: 50%; 
    left: 50%; 
    margin-top: -(element_height/2); 
    margin-left: -(element_width/2); 
} 
0

不知道關於它的工作,但嘗試添加overflow: hidden;a標籤