英文:
How to change position of arrows of Carousel using in Angular/ng-bootstrap?
问题
我能够使用encapsulation: ViewEncapsulation.None
和更改carousel-control-next-icon
的CSS样式来更改导航箭头的颜色。
我在StackOverflow上找到了其他答案的帮助。
但是,我在这里没有找到如何更改我的Carosel导航箭头位置的答案。
我有一个包含轮播图的主要卡片,我只想将导航箭头放在我的轮播图之外,放在ng-template之外...
这是我的当前模板:
<!-- This card will contain a carosel / O meu card vai ter um carrocel. -->
<div class="card rounded-3 whyus-carrocel bg-transparent bg-dark-subtle d-flex align-items-center">
<!-- The carosel itself / O carrocel em si. - Usa 100% da altura do card -->
<!-- Hidden Classes: carousel, slide. -->
<!--suppress AngularUndefinedBinding -->
<ngb-carousel *ngIf="cards.length > 0" class="bg-white shadow" [showNavigationIndicators]="false">
<!-- Layer/Camada 1: Role "Tablist". Classe: carousel-indicators. É o Navigation Indicators -->
<!-- Layer/Camada 2: Wrapper for slides, carousel-inner. -->
<ng-template ngbSlide *ngFor="let card of cards">
<!--suppress AngularNgOptimizedImage -->
<img [src]="card.caminhoImg" class="img-thumbnail card-img-top w-100" [alt]="card.textoAlternativo"
height="400" width="600">
<div class="card-body">
<header class="card-title h5">{{ card.cardTitulo }}</header>
<p class="card-text">{{ card.cardDescricao }}</p>
</div>
</ng-template>
<!-- Layer/Camada 3: Buttons. Carousel-control-prev e next. -->
</ngb-carousel>
</div>
这是应用在其中的CSS和TypeScript:
/* Styles applied with the help of dev-tools - Use it */
.whyus-carrocel {
height: 428px;
width: 690px;
}
/* Here I am on carousel/Dentro do carrocel: Inside/Dentro de ngb-carousel do Angular. */
.whyus-carrocel .carousel {
height: 100%;
width: 18rem;
}
.carousel-control-next-icon {
background-image: none;
background-color: rgb(13, 110, 253);
border-radius: 50%;
}
.carousel-control-prev-icon {
background-image: none;
background-color: rgb(13, 110, 253);
border-radius: 50%;
}
import { Component, ViewEncapsulation } from '@angular/core';
@Component({
selector: 'app-row-whyus',
// To be able to change carosel style/Mudar estilo do carrocel.
encapsulation: ViewEncapsulation.None,
// Etc
我尝试应用我在另一个问题中看到的方法,该方法只是告诉我将导航箭头的按钮隐藏为false,并在div之外创建一个新的按钮组,但它没有起作用。
我的最终结果应该是这样的:
< | CAROSEL | >
目前是这样的:
| < CAROSEL > |
导航箭头在轮播图内部 - 这是ng-bootstrap轮播图的默认行为。
我在这里尽力使用正确的拼写并表达我想要实现的内容...有人可以帮助我吗?
编辑:在我之前的尝试中,我尝试在ng-template中添加具有类的按钮,以查看HTML标签是否会覆盖ng-template的标签,但它甚至没有出现,也没有做到这一点。
英文:
I was able to change the colors of my navigation arrows using encapsulation: ViewEncapsulation.None
and changing CSS styles of carousel-control-next-icon
.
I did this with help of other answers at StackOverflow.
But, I did not find any answers here on how to change the positioning of the navigation arrows of my Carosel.
I have my main card with my carousel, and I just want to put my navigation arrows outside my carousel, outside ng-template...
This is my current template:
<!-- This card will contain a carosel / O meu card vai ter um carrocel. -->
<div class="card rounded-3 whyus-carrocel bg-transparent bg-dark-subtle d-flex align-items-center">
<!-- The carosel itself / O carrocel em si. - Usa 100% da altura do card -->
<!-- Hidden Classes: carousel, slide. -->
<!--suppress AngularUndefinedBinding -->
<ngb-carousel *ngIf="cards.length > 0" class="bg-white shadow" [showNavigationIndicators]="false">
<!-- Layer/Camada 1: Role "Tablist". Classe: carousel-indicators. É o Navigation Indicators -->
<!-- Layer/Camada 2: Wrapper for slides, carousel-inner. -->
<ng-template ngbSlide *ngFor="let card of cards">
<!--suppress AngularNgOptimizedImage -->
<img [src]="card.caminhoImg" class="img-thumbnail card-img-top w-100" [alt]="card.textoAlternativo"
height="400" width="600">
<div class="card-body">
<header class="card-title h5">{{ card.cardTitulo }}</header>
<p class="card-text">{{ card.cardDescricao }}</p>
</div>
</ng-template>
<!-- Layer/Camada 3: Buttons. Carousel-control-prev e next. -->
</ngb-carousel>
</div>
And this is the CSS and TypeScript applied in it:
/* Styles applied with the help of dev-tools - Use it */
.whyus-carrocel {
height: 428px;
width: 690px;
}
/* Here I am on carousel/Dentro do carrocel: Inside/Dentro de ngb-carousel do Angular. */
.whyus-carrocel .carousel {
height: 100%;
width: 18rem;
}
.carousel-control-next-icon {
background-image: none;
background-color: rgb(13, 110, 253);
border-radius: 50%;
}
.carousel-control-prev-icon {
background-image: none;
background-color: rgb(13, 110, 253);
border-radius: 50%;
}
import { Component, ViewEncapsulation } from '@angular/core';
@Component({
selector: 'app-row-whyus',
// To be able to change carosel style/Mudar estilo do carrocel.
encapsulation: ViewEncapsulation.None,
// Etc
I tried applying something I saw at another question, that just told me to hide the buttons using navigation arrows to false, and creating a new button group outside the div, but it did'nt work.
My final result would be something like this:
< | CAROSEL | >
At the moment, it's like this:
| < CAROSEL > |
The navigation arrows are inside the carosel - Which is the default behaviour of the ng-bootstrap carousel.
I tried my best here to use my spelling correct and say what I want to achieve... Can someone help me?
Edit: In my previous attempt, I tried adding the buttons with the classes inside the ng-template, to see if the HTML tags would override the ng-template ones, but it did'nt even appear and did not do that.
答案1
得分: 1
我通过在ng-template中包裹我的元素并在左侧/右侧给它添加padding来解决了这个问题,像这样:
<!-- The carosel itself / O carrocel em si. - Usa 100% da altura do card -->
<!-- Hidden Classes: carousel, slide. -->
<!--suppress AngularUndefinedBinding -->
<ngb-carousel *ngIf="cards.length > 0" [showNavigationIndicators]="false" class="shadow">
<!-- Layer/Camada 1: Role "Tablist". Classe: carousel-indicators. É o Navigation Indicators -->
<!-- Layer/Camada 2: Wrapper for slides, carousel-inner - Não aplicar classes aqui. -->
<ng-template ngbSlide *ngFor="let card of cards">
<!-- Container para envolver o card com os botões -->
<div class="px-5">
<!--suppress AngularNgOptimizedImage -->
<img [src]="card.caminhoImg" class="img-thumbnail card-img-top" [alt]="card.textoAlternativo"
height="400" width="600">
<div class="card-body">
<header class="card-title h5">{{ card.cardTitulo }}</header>
<p class="card-text">{{ card.cardDescricao }}</p>
</div>
</div>
</ng-template>
<!-- Layer/Camada 3: Buttons. Carousel-control-prev e next. -->
</ngb-carousel>
如果是这一行 <div class="px-5">
这是它的效果:
英文:
I was able to solve this by envolving
my elements inside the ng-template and give it a padding on right/left side, like this:
<!-- The carosel itself / O carrocel em si. - Usa 100% da altura do card -->
<!-- Hidden Classes: carousel, slide. -->
<!--suppress AngularUndefinedBinding -->
<ngb-carousel *ngIf="cards.length > 0" [showNavigationIndicators]="false" class="shadow">
<!-- Layer/Camada 1: Role "Tablist". Classe: carousel-indicators. É o Navigation Indicators -->
<!-- Layer/Camada 2: Wrapper for slides, carousel-inner - Não aplicar classes aqui. -->
<ng-template ngbSlide *ngFor="let card of cards">
<!-- Container para envolver o card com os botões -->
<div class="px-5">
<!--suppress AngularNgOptimizedImage -->
<img [src]="card.caminhoImg" class="img-thumbnail card-img-top" [alt]="card.textoAlternativo"
height="400" width="600">
<div class="card-body">
<header class="card-title h5">{{ card.cardTitulo }}</header>
<p class="card-text">{{ card.cardDescricao }}</p>
</div>
</div>
</ng-template>
<!-- Layer/Camada 3: Buttons. Carousel-control-prev e next. -->
</ngb-carousel>
Se the line <div class="px-5">
This is what it reproduced:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论