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.
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 .
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.
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
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With