本文介绍了CSS列布局下的多余空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个2列纯CSS网格,它可以工作,但是会导致两列下面都有多余的空间.
I have a 2 column CSS-only grid which works, however it causes excess space beneath both columns.
.
如果我从每个单元格中删除行内块,那么多余的空间并不是很糟糕,但是这是需要的,以防止网格包裹.我以为问题与垂直对齐有关,不过添加此内容似乎没有什么区别.有什么办法可以防止这个多余的空间?
If I remove inline-block from each cell the excess space is not so bad however this is needed to prevent the grid wrapping. I presumed the issue was with vertical-align, adding this appears to have made no difference though. Is there any way of preventing this excess space?
.columns {
-webkit-column-gap: 1.5em;
-moz-column-gap: 1.5em;
column-gap: 1.5em;
-webkit-column-fill: auto;
-moz-column-fill: auto;
column-fill: auto;
}
.columns__cell {
break-inside: avoid-column;
column-break-inside: avoid;
display: inline-block;
vertical-align: top;
width: 100%;
}
.columns--2 {
-moz-column-count: 2;
-webkit-column-count: 2;
column-count: 2;
}
结构:
<div class="column column--2">
<!-- repeated -->
<div class="widget__item poll column__cell">
<div class="widget__head clearfix">
***
</div>
<div class="widget__body">
***
</div>
</div>
<!-- repeated -->
</div>
推荐答案
我会使用float属性..inner是您在其中嵌套colLeft和colRight的容器.这应该可以解决您的问题.
I would use the float property..inner is the container in which you nest colLeft and colRight. This should fix your problem.
.inner {
overflow-x: hidden;
overflow-y: hidden;
position: relative;
margin: 0 auto;
width: 100%;
display: -webkit-box;
display: -moz-box;
display: -ms-flexbox;
display: -webkit-flex;
display: flex;
}
.colRight {
float: left;
width: 50%;
}
.colLeft {
padding-right: 10%;
float: right;
width: 50%;
}
这篇关于CSS列布局下的多余空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!