【问题标题】:How to center a IMG tag horizontaly and vertically using html and css in ie7?如何在ie 7中使用html和css将IMG标签水平和垂直居中?
【发布时间】:2013-01-15 13:03:59
【问题描述】:

我将“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;
}

谢谢你。

【问题讨论】:

  • 不完全确定你想在这里实现什么。您是否希望“a”标签比其中的图像更高更宽,然后在“a”标签内水平和垂直居中?

标签: html css internet-explorer-7


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    要使元素居中,请使用以下代码 sn-p:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多