Materialisecss卡分发

时间:2017-05-26 09:46:25

标签: html css angularjs materialize masonry

我在angularjs和materializecss的帮助下在一个网站上工作。我面临的问题是,我得到了下面两张卡片之间的空白区域。

我尝试了这个this解决方案但是卡片从上到下排序,我希望它们从左到右排序。我可以用漂浮物做些什么吗?我可以使用砖石,但我觉得很难让它上班。因为我需要在更改ng-repeat时更新它,当图像加载缓慢时,砌体不能达到我想要的效果。

也许有人可以指出我正确的方向。

<div class="container">
<div ng-controller="featured">
    <h1>Featured</h1>
    <input type="search" ng-model="q" placeholder="search..."/>
    <div class="row">
        <div class="cards-container">
            <div class="col s12 m6 l4" ng-repeat="x in data | filter:q as results" repeat-end="onEnd()">
                <div class="card" post-id="{{x.id}}">
                    <a style="display:block" href="#post/{{x.id}}">
                        <div class="card-image">
                            <img ng-src="{{x.thumb}}">
                            <span class="card-title">{{x.title | limitTocustom:30}}</span>
                        </div>
                    </a>
                    <div class="card-content">
                        <p>{{x.description}}</p>
                    </div>
                    <div class="card-action grey-text lighten-2" ng-animate="'animate'" style="padding:15px 15px 15px 15px !important;">
                        <div>
                            <!-- <span><span><i class="material-icons" style="margin-right:5px;">account_circle</i>{{x.author}}</span><span style="float:right;"><i class="material-icons red-text text-lighten-2" style="margin-right:5px;">favorite</i>{{x.points}}</span></span> -->
                            <span><i class="fa fa-user"></i> {{x.author}}</span>
                            <span style="float:right;"><i class="fa fa-heart"></i> {{x.points}}</span>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>
</div>

我找到的第一个解决方案 有了这个我可以配置我想要clearfix的div。因此,当用户使用较小的屏幕时,它将使用.col:nth-​​child(2n + 1)来完成。

@media only screen and (min-width: 601px) and (max-width: 993px) {
    .col:nth-child(2n+1) {
        clear: both;
    }
}
@media only screen and (min-width: 993px) and (max-width: 1400px) {
    .col:nth-child(3n+4) {
        clear: both;
    }
}
@media only screen and (min-width: 1400px) {
    .col:nth-child(3n+4) {
        clear: both;
    }
}

example

1 个答案:

答案 0 :(得分:0)

.card{
height:300px;
}

<div class="container">
<div ng-controller="featured">
    <h1>Featured</h1>
    <input type="search" ng-model="q" placeholder="search..."/>
    <div class="row">
        <div class="cards-container">
            <div class="col s12 m6 l4" ng-repeat="x in data | filter:q as results" repeat-end="onEnd()">
                <div class="card"  post-id="{{x.id}}">
                    <a style="display:block" href="#post/{{x.id}}">
                        <div class="card-image">
                            <img ng-src="{{x.thumb}}">
                            <span class="card-title">{{x.title | limitTocustom:30}}</span>
                        </div>
                    </a>
                    <div class="card-content">
                        <p>{{x.description}}</p>
                    </div>
                    <div class="card-action grey-text lighten-2" ng-animate="'animate'" style="padding:15px 15px 15px 15px !important;">
                        <div>
                            <!-- <span><span><i class="material-icons" style="margin-right:5px;">account_circle</i>{{x.author}}</span><span style="float:right;"><i class="material-icons red-text text-lighten-2" style="margin-right:5px;">favorite</i>{{x.points}}</span></span> -->
                            <span><i class="fa fa-user"></i> {{x.author}}</span>
                            <span style="float:right;"><i class="fa fa-heart"></i> {{x.points}}</span>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>
</div>

像这样给你的牌固定高度。它会解决你的问题