我正在使用ng-bootstrap为我的角度项目创建轮播。我成功地遵循了https://ng-bootstrap.github.io/#/components/carousel/examples所示的示例,现在屏幕中间有一个轮播。
我现在希望轮播占据整个屏幕宽度,而不是仅仅坐在中间。我该怎么做?
我尝试过在轮播中添加一个类,并像这样更改宽度:
组件HTML
<ngb-carousel *ngIf="images" class="myclass">
<ng-template ngbSlide>
<img [src]="images[0]" alt="Random first slide">
<div class="carousel-caption">
<h3>First slide label</h3>
<p>Nulla vitae elit libero, a pharetra augue mollis interdum.</p>
</div>
</ng-template>
<ng-template ngbSlide>
<img [src]="images[1]" alt="Random second slide">
<div class="carousel-caption">
<h3>Second slide label</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
</ng-template>
<ng-template ngbSlide>
<img [src]="images[2]" alt="Random third slide">
<div class="carousel-caption">
<h3>Third slide label</h3>
<p>Praesent commodo cursus magna, vel scelerisque nisl consectetur.</p>
</div>
</ng-template>
</ngb-carousel>
组件CSS
.myclass{
width: 100%;
}
答案 0 :(得分:0)
您必须将myclass
设置为图像。您正在使用引导程序,因此可以改用w-100
:
<ngb-carousel *ngIf="images">
<ng-template ngbSlide>
<img [src]="images[0]" alt="Random first slide" class="w-100">
<div class="carousel-caption">
<h3>First slide label</h3>
<p>Nulla vitae elit libero, a pharetra augue mollis interdum.</p>
</div>
</ng-template>
<ng-template ngbSlide>
<img [src]="images[1]" alt="Random second slide" class="w-100">
<div class="carousel-caption">
<h3>Second slide label</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
</div>
</ng-template>
<ng-template ngbSlide>
<img [src]="images[2]" alt="Random third slide" >
<div class="carousel-caption">
<h3>Third slide label</h3>
<p>Praesent commodo cursus magna, vel scelerisque nisl consectetur.</p>
</div>
</ng-template>
</ngb-carousel>
您可能还想使用object-fit:cover;
答案 1 :(得分:0)
您也可以这样做。而不是使用!Important的w-100
<img [src]="images[0]" alt="Random first slide" width="100%">
答案 2 :(得分:-1)
在此处的html标签中直接添加示例:
<img [src]="images[0]" alt="Random first slide" class="mh-100" style="width: 100%; height: 50vh">