Topic: Multi-item carousel, reduce space between small sized cards
She Jong Shon pro asked 6 years ago
mdb-carousel
, each mdb-card
's max width is 220px and I want to show 5 cards per slide showing in a single line.
Currently,
- space between the cards is too wide
- three cards are placed in a single line, but the rest of two cards are pushed to the bottom.
<mdb-carousel [isControls]="true" class="carousel-multi-item multi-animation" [type]="'carousel-multi-item'" [animation]="'slide'"[(activeSlideIndex)]="activeSlideIndex"(activeSlideChange)="activeSlideChange($event)"> <mdb-carousel-item *ngFor="let item of slides; let i = index"> <div class="col-md-4" *ngFor="let card of item"> <mdb-card style="max-width: 220px;"> <mdb-card-img [src]="card.img" alt="Card image cap"></mdb-card-img> <mdb-card-body> <mdb-card-title> <h4>{{card.title}}</h4> </mdb-card-title> <p>{{card.description}}</p> <a href="#" mdbBtncolor="primary" class="waves-light" mdbWavesEffect>{{card.buttonText}}</a> </mdb-card-body> </mdb-card> </div> </mdb-carousel-item> </mdb-carousel>
cards = [ { title:'Card Title 1', description:'Lorem ipsum dolor sit amet consectetur adipisicing elit. Ducimus totam hic similique vero architecto reprehenderit consequatur cum', buttonText:'Button', img:'https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20(34).jpg' }, { title:'Card Title 2', description:'Lorem ipsum dolor sit amet consectetur adipisicing elit. Ducimus totam hic similique vero architecto reprehenderit consequatur cum', buttonText:'Button', img:'https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20(34).jpg' }, { title:'Card Title 3', description:'Lorem ipsum dolor sit amet consectetur adipisicing elit. Ducimus totam hic similique vero architecto reprehenderit consequatur cum', buttonText:'Button', img:'https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20(34).jpg' }, { title:'Card Title 4', description:'Lorem ipsum dolor sit amet consectetur adipisicing elit. Ducimus totam hic similique vero architecto reprehenderit consequatur cum', buttonText:'Button', img:'https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20(34).jpg' }, { title:'Card Title 5', description:'Lorem ipsum dolor sit amet consectetur adipisicing elit. Ducimus totam hic similique vero architecto reprehenderit consequatur cum', buttonText:'Button', img:'https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20(34).jpg' }, { title:'Card Title 6', description:'Lorem ipsum dolor sit amet consectetur adipisicing elit. Ducimus totam hic similique vero architecto reprehenderit consequatur cum', buttonText:'Button', img:'https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20(34).jpg' }, { title:'Card Title 7', description:'Lorem ipsum dolor sit amet consectetur adipisicing elit. Ducimus totam hic similique vero architecto reprehenderit consequatur cum', buttonText:'Button', img:'https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20(34).jpg' }, { title:'Card Title 8', description:'Lorem ipsum dolor sit amet consectetur adipisicing elit. Ducimus totam hic similique vero architecto reprehenderit consequatur cum', buttonText:'Button', img:'https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20(34).jpg' }, { title:'Card Title 9', description:'Lorem ipsum dolor sit amet consectetur adipisicing elit. Ducimus totam hic similique vero architecto reprehenderit consequatur cum', buttonText:'Button', img:'https://mdbootstrap.com/img/Photos/Horizontal/Nature/4-col/img%20(34).jpg' }, ]; slides:any= [ [] ]; chunk(arr, chunkSize) { let R= []; for (let i=0, len=arr.length; i<len; i+=chunkSize) { R.push(arr.slice(i, i+chunkSize)); } return R; } ngOnInit() { this.slides = this.chunk(this.cards, 5); }
Damian Gemza staff answered 6 years ago
<mdb-carousel [isControls]="true" class="carousel-multi-item multi-animation" [type]="'carousel-multi-item'" [animation]="'slide'"> <mdb-carousel-item *ngFor="let item of slides; let i = index"> <div class="col-md-2" *ngFor="let card of item"> <mdb-card> <mdb-card-img [src]="card.img"alt="Card image cap"></mdb-card-img> <mdb-card-body> <mdb-card-title> <h4>{{card.title}}</h4> </mdb-card-title> <p>{{card.description}}</p><ahref="#"mdbBtncolor="primary"class="waves-light"mdbWavesEffect>{{card.buttonText}}</a> </mdb-card-body> </mdb-card> </div> </mdb-carousel-item> </mdb-carousel>
.carousel-multi-item .carousel-inner .carousel-item.active, .carousel-multi-item .carousel-item-next, .carousel-multi-item .carousel-item-prev { display: flex; }
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Resolved
- User: Pro
- Premium support: No
- Technology: MDB Angular
- MDB Version: 6.2.3
- Device: web
- Browser: chrome
- OS: windows 10
- Provided sample code: Yes
- Provided link: No