【发布时间】:2014-10-01 14:33:02
【问题描述】:
基本上,我有一个宽度设置为 100% 的 div,其中有一个 img 链接。 img 的宽度设置为自动,高度为 600 像素。链接区域延伸到整个 div 的宽度,在这种情况下是整个页面的宽度,而不仅仅是 img。
<div class="feature">
<a href="feature-page.html"><img src="feature.jpg" /></a>
</div>
.feature {
width: 100%;
height: auto;
}
.feature a img {
width: auto;
height: 600px;
display: block;
margin: auto;
}
我不想将 div 的宽度更改为设定值(这确实有效),因为我希望以后能够添加可能具有不同纵横比的图像。有没有人有办法解决吗?谢谢。
如果您手动设置 div 的宽度,这会显示结果:http://jsfiddle.net/L1xanprh/4/ 我也尝试将 div 宽度也设置为 auto,它与宽度为 100% 的问题相同。
【问题讨论】:
-
div 宽度是什么的 100%?