【发布时间】:2021-12-31 20:24:04
【问题描述】:
我无法弄清楚如何正确地为我的 weather-form-div 设置边距,因为当我尝试设置边距时,App 类的 div 会相应地移动。我希望 App 类的 div 的大小是固定的。
*{
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
background-image: url('https://wallpapercave.com/wp/wp2733241.png');
background-position: center;
background-size: cover;
background-repeat: no-repeat;
min-height: 100vh;
}
.App{
height: 100vh;
width: 100vw;
background: rgba(0,0,0,0.4);
}
.weather-form-div{
border: 4px solid red;
width: 372px;
margin: 50px auto;
}
.weather-form{
display: flex;
flex-direction: column;
}
【问题讨论】:
-
试试
height: calc(100vh - 50px);和width一样 -
它有效,谢谢。顺便说一句,使用 display flex 也可以解决这个问题,但我不知道原因。