【发布时间】:2020-08-07 22:52:40
【问题描述】:
我有一个弹性盒子容器,里面有一个子元素。当屏幕尺寸缩小时,我希望孩子也缩小。这是我现有的代码:
HTML:
<div class="container">
<div class="child"></div>
</div>
CSS:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.child {
width: 570px;
height: 500px;
background-color: red;
}
有谁知道如何做到这一点?谢谢。
更新:
.container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.child {
flex-basis: 200px;
width: 800px;
background-color: red;
}
更新 2:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
max-width: 570px;
}
.child {
width: 100%;
height: 500px;
background-color: red;
}
更新编号 3。注意这没有弯曲方向,因此默认为列:
.container {
display: flex;
align-items: center;
justify-content: center;
padding: 0 20px;
}
.child {
background-color: red;
width: 800px;
height: 800px;
}
【问题讨论】:
-
评论不用于扩展讨论;这个对话是moved to chat。