我试图做到这一点电网:我怎样才能做到这一点的CSS网格
在某种程度上说,如果可能的话,不使用的列(我知道它使用的列或引导是很容易),但,我假装是用角度做一个ng-repeat,这样我就不必担心新闻的顺序,所以我只是从列表中取数据并让CSS
完成对齐的工作。认为最好的方式应该是使用第十一个孩子。新闻订单将从更新到最后,如图所示1-7。
到目前为止,这是我的tried。
.main-feed .feed-item {
margin: 1em 1%;
float: left;
background-color: #008edb;
position: relative;
}
.main-feed .feed-item:nth-child(1) {
width: 48%;
height: 500px;
float: left;
}
.main-feed .feed-item:nth-child(2) {
width: 48%;
height: 300px;
float: left;
}
.main-feed .feed-item:nth-child(3) {
width: 23%;
height: 300px;
float: left;
clear: left;
}
.main-feed .feed-item:nth-child(4) {
width: 23%;
height: 400px;
float: left;
}
.main-feed .feed-item:nth-child(5) {
width: 23%;
height: 100px;
float: left;
}
.main-feed .feed-item:nth-child(6) {
width: 23%;
height: 100px;
float: right;
}
.main-feed .feed-item:nth-child(7) {
width: 48%;
height: 100px;
float: right;
}
<section class="main-feed">
<div class="wrapper">
<!--This is what i want to ng-repeat-->
<article class="feed-item">
<h1>1</h1>
</article>
<article class="feed-item">
<h1>2</h1>
</article>
<article class="feed-item">
<h1>3</h1>
</article>
<article class="feed-item">
<h1>4</h1>
</article>
<article class="feed-item">
<h1>5</h1>
</article>
<article class="feed-item">
<h1>6</h1>
</article>
<article class="feed-item">
<h1>7</h1>
</article>
</div>
</section>
我怎样才能让5,6,7至略低于2对齐?
任何帮助表示赞赏。
,如果你有不同高度这就需要一个JavaScript的解决方案。编码相当完善,但是https://masonry.desandro.com/已经做得非常好。无需重新发明轮子:) – WizardCoder
请检查此css功能,这是你想要做的。 (https://css-tricks.com/snippets/css/complete-guide-grid/) –