【发布时间】:2014-01-11 03:45:07
【问题描述】:
我有一个绝对定位的 div,其中包含百分比高度和图像。该图像的高度为 100%,宽度为 auto。调整视口高度时,绝对 div 不会调整其宽度,图像要么被截断,要么你会看到 div 的背景。
CSS
div {
position: absolute;
overflow: hidden;
height: 50%;
bottom: 80px;
left: 5%;
background: blue;
}
img {
height: 100%;
width: auto;
display: block;
}
HTML
<p>adjust the height of the viewport</p>
<div>
<img src="http://lorempixel.com/400/200" />
</div>
【问题讨论】:
-
这里是a link to an answer with a JS hack,其中will fix your issue。线程中的其他答案也可能值得一读,似乎无法仅使用 CSS 修复。这是an answer which sheds some more light on why things behave they way they behave的链接。
-
感谢 Mathijs。我搜索并搜索了类似的问题。但看起来我无法在搜索中找到正确的关键字来获取您引用的关键字。
标签: html css responsive-design