自动高度去除浮​​动

Auto height removing float

我编写了一些代码,其中 "section" 当内容在里面时自动确定高度,但是,我想在同一行中有多个列,并且这些列当前正在堆叠。

如何在不使用 float 元素的情况下将列设置到同一行,因为它会带走该部分的自动高度?

.section {
    width:100%;
    padding-top: 60px;
    padding-right: 0px;
    padding-bottom: 62px;
    padding-left: 0px;
    background-color: #f5f5f5;
    position: relative;
}

.row {
    position: relative;
    width: 100%;
    max-width: 1080px;
    margin: auto;
    padding: 33px 0;
}

.column{
    width: 100%;
    position: relative;
    z-index: 9;
}

.container {
    overflow: hidden !important;
    position: relative;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: transparent;
    width: 300px;
    height: 500px;
    border-radius: 0px;
}
 <div class="section">
  <div class="row">
   <div class="column">
    <div class="container">
     <img src="img.png">
     <div class="content_block">
                        <div class="text">
      <h2>Title</h2>
                        <a>2 reports</a>
                        </div>
     </div>
    </div>
   </div>
            <div class="column">
   </div>
  </div>
 </div>

最简单的方法是使用 flexbox。

所以只需添加..

display: flex;

..你可能会删除宽度(或将其设置为 50%)

.row {
    display: flex;
    position: relative;
    width: 50%;
    max-width: 1080px;
    margin: auto;
    padding: 33px 0;
}

当然还有其他方法(colspan、inline-block),但 flexbox 会给你均匀高度的列并使任何其他格式更容易。