Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a new row of cards using ngFor and bootstrap 4

I'm trying to use the card group functionality of Bootstrap 4 with Angular ngFor.

Here is the HTML I have for now, but I can't find how to break to a new line after 3 items have been inserted:

<div class="row card-group">
    <div *ngFor="let presentation of presentations" class="col-4 card">
        <a [routerLink]="['/presentation', presentation._id]">{{presentation.title}}</a>
    </div>
</div>

I've seen other answer saying to use the clearfix class, but this has not worked so far for me.

like image 356
otusweb Avatar asked May 02 '17 20:05

otusweb


People also ask

How do I make 5 cards in a row in bootstrap?

In latest Bootstrap >= 4.4 : Use the brand new row-cols-* classes Add row-cols-5 to your row containing elements. So no custom CSS needed. If you want to break on Extra Large + Large + Medium + Small screen as you need then use row-cols-sm-2 row-cols-md-3 row-cols-lg-4 row-cols-xl-5 in row .

How can make card Content Center in bootstrap?

You can add a justify-content-center class in it, to make it center the content in a flexbox way. Moreover, if you don't need it to act like a flexbox at all, feel free to remote the d-flex class.


2 Answers

You need a wrapping div with the class col-4 arroud the <div> with card class. thats how grid layout works.

see using grid markup section here: https://v4-alpha.getbootstrap.com/components/card/#using-grid-markup

so:

<div class="row card-group">
    <div class="col-4"  *ngFor="let presentation of presentations">
        <div class="card">
            <a [routerLink]="['/presentation', presentation._id]">{{presentation.title}}</a>
        </div>
    </div>
</div>

sample plunker: https://plnkr.co/edit/8LDBMorXBB1OqI0bolS6?p=preview

like image 184
Ahmed Musallam Avatar answered Oct 19 '22 18:10

Ahmed Musallam


Thanks to @zimSystem I found something that works.

<div class="row">
    <div *ngFor="let presentation of presentations" class="col-4 card">
        <a [routerLink]="['/presentation', presentation._id]"><img class="card-img-top" src="..." alt="Card image cap"></a>
        <div class="card-block">
            ...
        </div>
    </div>
</div>
like image 24
otusweb Avatar answered Oct 19 '22 19:10

otusweb