【问题标题】:How to make a div full sized in CSS?如何在 CSS 中制作一个全尺寸的 div?
【发布时间】: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 也可以解决这个问题,但我不知道原因。

标签: html css margin


【解决方案1】:

尝试使用 flex 属性,因为 flex 容器扩展项目以填充可用空间或缩小它们以防止溢出

【讨论】:

    猜你喜欢
    • 2021-04-26
    • 1970-01-01
    • 2017-03-25
    • 1970-01-01
    • 2019-10-19
    • 1970-01-01
    • 2012-01-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多