ng-bootstrap 的 Carousel 看起来不完整 window 但至少看起来不错

ng-bootstrap's Carousel not looking right in full window but looks good on minimum

我正在学习 ng-bootstrap 并且真的在研究使用他们的 carousel 实现。我查看了他们的官方文档和示例,他们可以使用半个 window 但完整 window 看起来不太好。我怎样才能使轮播看起来完整window?

我尝试分配 ngb-carousel 一个 ID 并将其显示更改为内嵌,但它没有用。

link(在下面列出)带你到官方文档,如果你点击顶部的 StackBlitz,你可以 运行 代码。 (抱歉,我试图在此处向 stackBlitz 的示例提供 link,但它一直重定向到主页)。

link 到官方文档(我是第一个例子的代码!!!!): https://ng-bootstrap.github.io/#/components/carousel/examples

这是复制的代码: app.component.ts

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

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html'
})
export class AppComponent {
}

app.module.ts

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';

import { NgbdCarouselBasic } from './carousel-basic';

@NgModule({
  imports: [BrowserModule, NgbModule],
  declarations: [NgbdCarouselBasic],
  exports: [NgbdCarouselBasic],
  bootstrap: [NgbdCarouselBasic]
})
export class NgbdCarouselBasicModule {}

app.component.html

<div class="container-fluid">

  <hr>

  <p>
    This is a demo example forked from the <strong>ng-bootstrap</strong> project: Angular powered Bootstrap.
    Visit <a href="https://ng-bootstrap.github.io/" target="_blank">https://ng-bootstrap.github.io</a> for more widgets and demos.
  </p>

  <hr>

  <ngbd-carousel-basic></ngbd-carousel-basic>
</div>

轮播-basic.html

<ngb-carousel *ngIf="images">
  <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>

carouselbasic.ts

import {Component, OnInit} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {map} from 'rxjs/operators';

@Component({selector: 'ngbd-carousel-basic', templateUrl: './carousel-basic.html'})
export class NgbdCarouselBasic implements OnInit {
  images: Array<string>;

  constructor(private _http: HttpClient) {}

  ngOnInit() {
    this._http.get('https://picsum.photos/list')
        .pipe(map((images: Array<{id: number}>) => this._randomImageUrls(images)))
        .subscribe(images => this.images = images);
  }

  private _randomImageUrls(images: Array<{id: number}>): Array<string> {
    return [1, 2, 3].map(() => {
      const randomId = images[Math.floor(Math.random() * images.length)].id;
      return `https://picsum.photos/900/500?image=${randomId}`;
    });
  }
}

同样,它(旋转木马)在半屏中看起来不错,但在全屏中看起来完全不对(就像你在旋转木马中看不到右箭头一样)。它反应灵敏,但我不知道我该怎么做才能让它在全屏模式下看起来像旋转木马。

最近,我正在尝试将其添加到我自己的网站,当我现在尝试添加它时,旋转木马的右侧看起来完全关闭(在右侧看不到旋转木马)。我确定如果我可以解决轮播的全屏问题,那么它就会在我的页面上运行。

编辑:-------------------------------- -- 我无法解决这个额外的边距,但我试图将 ng-carousel 居中,它使左右图标确实一起出现。

2 CSS 更改以满足您的要求:

.carouselImage { width:100%;  }
::ng-deep .container-fluid { padding:0 !important; }

第一个确保无论图像大小如何,宽度都是 100%...对于填充,我们只是覆盖了因为 container-fluid class 而存在的填充

完成working demo here