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

前端 未结 3 1529
猫巷女王i
猫巷女王i 2021-02-06 00:14

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

相关标签:
3条回答
  • 2021-02-06 00:44

    The card-group is preventing the col's from wrapping to the next "line". Place the cards inside the columns, and instead use h-100 to make the cards full/same height. This way the Angular code won't need to iterate the row.

        <div class="row">
            <div class="col-4">
                <div class="card h-100">
                    ..
                </div>
            </div>
            <div class="col-4">
                <div class="card h-100">
                ..
                </div>
            </div>
        </div>
    

    http://www.codeply.com/go/yWdYL5GrTu

    0 讨论(0)
  • 2021-02-06 00:48

    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

    0 讨论(0)
  • 2021-02-06 00:49

    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>
    
    0 讨论(0)
提交回复
热议问题