0

我将“a”标签放在我的html中并添加相对于它的位置,然后在“a”标签中附加“img”标签并添加绝对位置,左0,右0,上0,下0,边距自动到“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;
}

感谢您。

4

2 回答 2

0

不确定它是否有效,但尝试添加overflow: hidden;a标签的样式

于 2013-01-31T12:21:50.750 回答
0

要使元素居中,请使用以下代码片段:

.centered {
  position: based on your choice;
  top: 50%;
  left: 50%;
  margin-top: -(element_height/2);
  margin-left: -(element_width/2);
}
于 2013-01-31T12:41:10.650 回答