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>
&#13;
内部div与特定像素如何适合屏幕高度或宽度,CSS 保持比率相同?
答案 0 :(得分:0)
喜欢这个?:
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;
}
&#13;
<div class="outer">
<div class="inner"></div>
</div>
&#13;