简体   繁体   中英

Angular/ng-bootstrap - Carousel Arrow Customization

I'm trying to change the positioning and icon of the given control arrows by bootstrap. I've tried to adress "carousel-control-prev-icon" & "carousel-control-next-icon", but nothing changes. Does anyone know a proper solution?

HTML:

<div class="container">
  <div class="row">
    <div class="col-12">
      <ngb-carousel *ngIf="images">
        <ng-template ngbSlide>
          <img [src]="images[0]" alt="Random first slide">
        </ng-template>
        <ng-template ngbSlide>
          <img [src]="images[1]" alt="Random second slide">
        </ng-template>
        <ng-template ngbSlide>
          <img [src]="images[2]" alt="Random third slide">
        </ng-template>
      </ngb-carousel>
  </div>
  </div>
</div>

CSS:

ngb-carousel {
    width: 900px;
}

.carousel-control-prev-icon{
    background-image: url('https://apufpel.com.br/assets/img/seta_prim.png')
 }
 .carousel-control-next-icon{
   background-image: url('https://apufpel.com.br/assets/img/seta_ult.png')
 }

TypeScript:

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})

export class AppComponent {

  images = ['assets/images/image1.jpg', 'assets/images/image2.jpg', 'assets/images/image3.jpg'];

}

Thanks in advance, Tim

Try to make your CSS including important because of NGB carousel CSS override this CSS that you are including into your component.css file as below

ngb-carousel {
  width: 900px;
}

.carousel-control-prev-icon{
 background-image: url('https://apufpel.com.br/assets/img/seta_prim.png') !important;
}
.carousel-control-next-icon{
   background-image: url('https://apufpel.com.br/assets/img/seta_ult.png')!important;
}

Hope this will help!!

I am using angular-13 and bootstrap 5. To change carousel arrows in a particular component, I had to add::ng-deep for it to work.

::ng-deep .carousel-control-prev-icon {
    background-image: url('https://apufpel.com.br/assets/img/seta_prim.png') !important;
}

::ng-deep .carousel-control-next-icon {
    background-image: url('https://apufpel.com.br/assets/img/seta_ult.png') !important;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM