0
如何居中最大宽度和最大高度的div,但也保持宽高比?居中最大宽度和高度的div启用并保持长宽比
到目前为止我的代码中心格,但它不保持6的纵横比:5(高度:宽度)
#main-content {
margin: 0 auto;
width: 100%;
max-width: 1200px;
height: 100%;
height: 500px;
background-color: #953d44;
position: relative;
}
#container {
width: 80%;
height: 80%;
max-height: 600px;
max-width: 500px;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
position: absolute;
background-color: cornflowerblue;
}
<div id="main-content">
<div id="container"></div>
</div>
https://codepen.io/timsim/pen/dWMbqR
研究关键字:填充底劈如果我添加填充到容器 – CBroe
,一些奇怪的东西开始发生 – sanjihan
@sanjihan你检查这https://www.w3schools.com/howto/howto_css_aspect_ratio.asp –