Basically, I've got a div with width set to 100%, within which there is an img link. The img's width is set to auto with a height of 600px. The link area stretches over the width of the whole div, in this case the width of the whole page, rather than just the img.img <a href> link stretches to full width of parent div instead of only covering 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;
}
I don't want to change the div's width to a set value (which does work), because I want to be able to add images later on that may have different aspect ratios. Does anyone have a solution? thanks.
This shows the result if you set the width of the div manually: http://jsfiddle.net/L1xanprh/4/我也尝试只是将div宽度设置为auto,它与宽度为100%的游戏存在相同的问题。
div宽度是100%的什么? – 2014-10-01 06:10:23