自动高度移除浮动

时间:2017-12-14 16:41:29

标签: html css css-float

我已经在"部分"中制作了一些代码。当内容在里面时,它会自动确定高度,但是,我希望在同一行中有多个列,并且列当前正在堆叠。

如何在不使用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>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

最简单的方法是使用flexbox。

所以只需添加..

display: flex;

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

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

当然还有其他方法(colspan,inline-block),但flexbox会为你提供偶数高度的列,并使任何其他格式更容易。