如何在Angular/ng-bootstrap中更改Carousel箭头的位置?

huangapple go评论97阅读模式
英文:

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:

        &lt;!-- This card will contain a carosel / O meu card vai ter um carrocel. --&gt;
        &lt;div class=&quot;card rounded-3 whyus-carrocel bg-transparent bg-dark-subtle d-flex align-items-center&quot;&gt;

          &lt;!-- The carosel itself / O carrocel em si. - Usa 100% da altura do card --&gt;
          &lt;!-- Hidden Classes: carousel, slide. --&gt;
          &lt;!--suppress AngularUndefinedBinding --&gt;
          &lt;ngb-carousel *ngIf=&quot;cards.length &gt; 0&quot; class=&quot;bg-white shadow&quot; [showNavigationIndicators]=&quot;false&quot;&gt;
            &lt;!-- Layer/Camada 1: Role &quot;Tablist&quot;. Classe: carousel-indicators. &#201; o Navigation Indicators --&gt;

            &lt;!-- Layer/Camada 2: Wrapper for slides, carousel-inner. --&gt;
            &lt;ng-template ngbSlide *ngFor=&quot;let card of cards&quot;&gt;
              &lt;!--suppress AngularNgOptimizedImage --&gt;
              &lt;img [src]=&quot;card.caminhoImg&quot; class=&quot;img-thumbnail card-img-top w-100&quot; [alt]=&quot;card.textoAlternativo&quot;
                   height=&quot;400&quot; width=&quot;600&quot;&gt;
              &lt;div class=&quot;card-body&quot;&gt;
                &lt;header class=&quot;card-title h5&quot;&gt;{{ card.cardTitulo }}&lt;/header&gt;
                &lt;p class=&quot;card-text&quot;&gt;{{ card.cardDescricao }}&lt;/p&gt;
              &lt;/div&gt;
            &lt;/ng-template&gt;

            &lt;!-- Layer/Camada 3: Buttons. Carousel-control-prev e next. --&gt;

          &lt;/ngb-carousel&gt;

        &lt;/div&gt;

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 &#39;@angular/core&#39;;

@Component({
  selector: &#39;app-row-whyus&#39;,

  // 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>

如果是这一行 &lt;div class=&quot;px-5&quot;&gt;

这是它的效果:

如何在Angular/ng-bootstrap中更改Carousel箭头的位置?

英文:

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:

          &lt;!-- The carosel itself / O carrocel em si. - Usa 100% da altura do card --&gt;
          &lt;!-- Hidden Classes: carousel, slide. --&gt;
          &lt;!--suppress AngularUndefinedBinding --&gt;
          &lt;ngb-carousel *ngIf=&quot;cards.length &gt; 0&quot; [showNavigationIndicators]=&quot;false&quot; class=&quot;shadow&quot;&gt;
            &lt;!-- Layer/Camada 1: Role &quot;Tablist&quot;. Classe: carousel-indicators. &#201; o Navigation Indicators --&gt;

            &lt;!-- Layer/Camada 2: Wrapper for slides, carousel-inner - N&#227;o aplicar classes aqui. --&gt;
            &lt;ng-template ngbSlide *ngFor=&quot;let card of cards&quot;&gt;

              &lt;!-- Container para envolver o card com os bot&#245;es --&gt;
              &lt;div class=&quot;px-5&quot;&gt;

                &lt;!--suppress AngularNgOptimizedImage --&gt;
                &lt;img [src]=&quot;card.caminhoImg&quot; class=&quot;img-thumbnail card-img-top&quot; [alt]=&quot;card.textoAlternativo&quot;
                     height=&quot;400&quot; width=&quot;600&quot;&gt;
                &lt;div class=&quot;card-body&quot;&gt;
                  &lt;header class=&quot;card-title h5&quot;&gt;{{ card.cardTitulo }}&lt;/header&gt;
                  &lt;p class=&quot;card-text&quot;&gt;{{ card.cardDescricao }}&lt;/p&gt;
                &lt;/div&gt;

              &lt;/div&gt;

            &lt;/ng-template&gt;

            &lt;!-- Layer/Camada 3: Buttons. Carousel-control-prev e next. --&gt;
          &lt;/ngb-carousel&gt;

Se the line &lt;div class=&quot;px-5&quot;&gt;

This is what it reproduced:

如何在Angular/ng-bootstrap中更改Carousel箭头的位置?

huangapple
  • 本文由 发表于 2023年8月9日 02:24:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/76862256.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定