【发布时间】:2012-02-22 16:55:07
【问题描述】:
我只是想知道这是浏览器渲染问题还是不正确的 css。 以定义的纵横比缩放 div 的一种好方法是使用透明图像作为子元素。 我在这里有一个小演示。下需要这个问题。
但是如果我想要 100% 的高度,为什么它不能很好地工作。
我在 FF10、Safari 5.1.2、IE8 和 IE9 中对此进行了测试。 (似乎只有 ie8 可以正确渲染...)
希望有人能解释这个问题,也许能想出一个解决方案。
问候, 里克
<!DOCTYPE html>
<html lang="uk">
<head>
<title>test</title>
<style>
html
, body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
background: green;
}
/* AUTO WIDTH - doesnt render correct when scaling the browser window to a smaller size */
.holder1 {
position: relative;
display: inline-block;
height: 100%;
width: auto;
background: yellow;
border-right: 1px solid red;
}
.holder1 .ratio {
display: block;
height: 100%;
width: auto;
}
/* AUTO HEIGHT - works fine */
.holder2 {
position: relative;
display: inline-block;
height: auto;
width: 100%;
background: yellow;
border-right: 1px solid red;
}
.holder2 .ratio {
display: block;
height: auto;
width: 100%;
}
</style>
</head>
<body>
<span class="holder1">
<img src="/images/empty_image.png" class="ratio" alt="Ratio image">
</span>
</body>
</html>
【问题讨论】:
-
width属性对<span>没有意义(因为它有display: inline),所以它对.holder2 没有任何作用。 -
@Alexander .hoder2 实际上并未在演示中使用(未出现在标记中)
标签: css image aspect-ratio