Flexbox容器中的CSS纵横比
我正在尝试制作div
,以填充其父级的所有可用高度,同时保持16/9的长宽比。但是,它填充了宽度,因此无法保持我设置的纵横比。关于如何解决此问题有什么建议吗?
<div class="outer">
<div class="problem"></div>
<div class="inner"></div>
</div>
.outer {
height: 100vh;
display: flex;
flex-direction: column;
}
.problem {
height: 200px;
}
.inner {
aspect-ratio: 16/9;
background-color: blue;
}
html,body {
margin: 0;
font-family: sans-serif;
}
jsfiddle: https://jsfiddle.net/cqhtb8sw/
I'm trying to make a div
that fills all available height of its parent, while maintaining a 16/9 aspect ratio. However, it's filling the width and thus not keeping the aspect ratio I've set. Any advice on how to fix this?
<div class="outer">
<div class="problem"></div>
<div class="inner"></div>
</div>
.outer {
height: 100vh;
display: flex;
flex-direction: column;
}
.problem {
height: 200px;
}
.inner {
aspect-ratio: 16/9;
background-color: blue;
}
html,body {
margin: 0;
font-family: sans-serif;
}
JSFiddle: https://jsfiddle.net/cqhtb8sw/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是由于Flexbox所致,您可以在内部样式中添加它:
It's due to flexbox, you can add this in your inner styles: