Im 브라우저의 렌더링 문제인지 또는 CSS의 오류인지 궁금합니다. 정의 된 종횡비에서 div를 축척하는 좋은 방법은 투명한 이미지를 자식 요소로 사용하는 것입니다. 여기에 작은 데모가 있습니다. 이 질문이 필요합니다.CSS와 이미지를 사용하는 종횡비가 올바르게 렌더링되지 않습니까?
하지만 100 % 높이를 원한다면 왜 제대로 작동하지 않습니까?
필자는 FF10, Safari 5.1.2, IE8 및 IE9에서이를 테스트했습니다. (ie8 만 올바르게 렌더링되는 것 같습니다 ...)
누군가가 문제를 설명하고 해결책을 생각해 낼 수 있기를 바랍니다. 당신은, 당신이 폭에 대한 자동 설정시 width:auto
와 width:100%
사이
1.Different : 질문을 본 후
감사합니다, 릭
<!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' 속성은''(왜냐하면'display : inline'을가집니다)에 적합하지 않으므로 .holder2에 대해서는 아무 일도하지 않습니다. –
@Alexander .hoder2는 데모에서 실제로 사용되지 않습니다 (마크 업에는 표시되지 않습니다). –