body {
margin: 0;
background-color: #2196F3;
}
.outer {
height: 100vh;
}
.inner {
width: 500px;
height: 1000px;
position: relative;
left: 50%;
transform: translateX(-50%);
background-color: #FF5722;
}
<div class="outer">
<div class="inner"></div>
</div>
如何使具有特定像素的内部 div 与屏幕高度或宽度保持一致,CSS 保持比率相同?
像这样?:
body {
margin: 0;
background-color: #2196F3;
}
.outer {
height: 100vh;
width: 100%;
}
.inner {
width: calc(100% - 40px);
height: calc(100% - 40px);
background-color: #FF5722;
margin-top: 20px;
margin-left: 20px;
}
<div class="outer">
<div class="inner"></div>
</div>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句