html - 使用 float 时保持底部边距

标签 html css sass

我正在尝试使用“float: left”创建网格布局,但这会导致第二行忽略指定的底部边距并向上移动到第一行的正下方。但是,第二行和第三行之间的边距按预期工作。

我尝试在行类上使用“clearfix: both”和“overflow: auto”。

    <div class="row one">
      <div class="col-1-of-2">Col 1 of 2</div>
      <div class="col-1-of-2">Col 1 of 2</div>
    </div>

    <div class="row two">
      <div class="col-1-of-3">Col 1 of 3</div>
      <div class="col-1-of-3">Col 1 of 3</div>
      <div class="col-1-of-3">Col 1 of 3</div>
    </div>

    <div class="row three">
      <div class="col-1-of-3">Col 1 of 3</div>
      <div class="col-2-of-3">Col 2 of 3</div>
    </div>     
.row {
  max-width: 114rem;
  background-color: #eee;
  margin: 0 auto;           

  &:not(:last-child){
      margin-bottom: 8rem; 
  }

  .col-1-of-2 {
    width: calc((100% - 6rem) / 2); 
    background-color: orangered;
    float: left;

    &:not(:last-child) {
      margin-right: 6rem; 
    }
  }
}

我希望在第一行和第二行之间应用 8rem 的底部边距。

最佳答案

你可以让你的第一行 display: flex;

.row {
    .one {
        display: flex;
    }

    ...
}

关于html - 使用 float 时保持底部边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56448129/

相关文章:

css - Webpack scss 和 css 模块 react - 意外的标记字符串

css - RAILS 3.1 中 css 的条件实时编译

css - Scss,目标类和事件类

javascript - jquery 在其 div 元素之外追加元素

javascript - Jquery + GSAP 从 onComplete 函数访问本地计算的值

html - Bootstrap 4 我的 col 不会在移动设备中排队

javascript - 当鼠标光标离开 div 时获取悬停的最后一个事件类?

html - 将哪些不可见的内容添加到 div 以使其显示在页面中?

javascript - 屏幕上的完整横幅宽度

css - 灰度背景 Css 图像