有padding诀窍,已经回答了,但我使用另一种方法,包含两个嵌套的div.
父母一个,我设置了宽度.孩子一,我使用height值作为容器单位vw- (意味着视口宽度).
效果很好,请看这里(调整视口大小)
<div>
<div></div>
</div>
Run Code Online (Sandbox Code Playgroud)
CSS:
div {
width: 100%;
}
div > div {
background: silver;
height: 10vw;
}
Run Code Online (Sandbox Code Playgroud)
我用这个
.aspect-ratio {
max-width: 100%;
}
.aspect-ratio:before {
content: '';
display: block;
width: 100%;
padding-bottom: ({height-aspect} / {width-aspect} * 100)%; // for 3 x 4, for instance: 75%
}
Run Code Online (Sandbox Code Playgroud)
如果你不喜欢我,你可以做一个混合:
.aspectRatio(@widthAspect, @heightAspect) {
@aspect: @heightAspect/@widthAspect * 100;
max-width: 100%;
&:before {
content: '';
display: block;
width: 100%;
padding-bottom: ~"@{aspect}%";
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
329 次 |
| 最近记录: |