垂直对齐图像居中溢出:隐藏

时间:2009-07-14 18:42:16

标签: css vertical-alignment

<div style="overflow:hidden; height:100px; width:100px;">
<img src="etc.jpg" width:"100px" /></div>

img我有一个divimg的高度未定义,但大于div的100px。

我想垂直居中img并隐藏顶部和底部溢出。

我仍然无法理解如何做到这一点......

丹尼尔

2 个答案:

答案 0 :(得分:0)

您可以尝试以负百分比设置图像的margin-top属性。例如;

div img {margin-top: -50%;}

只需使用百分比值,你就应该找到有用的东西。

答案 1 :(得分:-1)

这对你有用吗?

 <div style="overflow:hidden; height:100px; width:100px;">
   <image src="etc.jpg" style="width:100px; position: relative; bottom: 25%;" />
 </div>

嗯,当图像合适时,结果有点奇怪

相关问题