Bootstrap 轮播仅显示第一张图片,即使它正在滑动到下一张图片

Bootstrap carousel shows first image only even though it's sliding to the next ones

我的 bootstrap 轮播包含 4 张图片。 sliding/carousel 本身工作正常,但不知何故只显示第一张图片,而当滑动到图片 2-4 时,屏幕仅滑动到白色 space,显示图片描述。

<div id="carousel" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
  <li data-target="#carousel" data-slide-to="0" class="active"></li>
  <li data-target="#carousel" data-slide-to="1"></li>
  <li data-target="#carousel" data-slide-to="2"></li>
  <li data-target="#carousel" data-slide-to="3"></li>
</ol>
<div class="carousel-inner" role="listbox">
  <div class="item active">
    <img class="d-block img-fluid" src="{{ asset('img/key-visuals/01-lh.jpg') }}" alt="First slide">
  </div>
  <div class="item">
    <img class="d-block img-fluid" src"{{ asset('img/key-visuals/02-lx.jpg') }}" alt="Second slide">
  </div>
  <div class="item">
    <img class="d-block img-fluid" src"{{ asset('img/key-visuals/03-os.jpg') }}" alt="Third slide">
  </div>
  <div class="item">
    <img class="d-block img-fluid" src"{{ asset('img/key-visuals/04-sn.jpg') }}" alt="Fourth slide">
  </div>
</div>
<a class="carousel-control left" href="#carousel" data-slide="prev">
  <span class="icon-prev left"></span>
</a>

<a class="carousel-control right" href="#carousel" data-slide="next">
  <span class="icon-next right"></span>
</a>

目前只显示第一张图片(01-lh),但是当例如将我的第二张图片 (02-lx) 中的 src 而不是第一张图片放在一起,该图片会显示,但其他图片会显示 none。等等..

有什么想法吗?

您正在使用 Bootstrap 4 但仍然依赖过时的 Bootstrap 3 class 名称。根据 Bootstrap 的更新指南,item 应该是 carousel-item

https://getbootstrap.com/docs/4.0/components/carousel/#example

<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
  <ol class="carousel-indicators">
    <li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
    <li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
    <li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
  </ol>

  <div class="carousel-inner">
    <div class="carousel-item active">
      <img class="d-block w-100" src="..." alt="First slide">
    </div>

    <div class="carousel-item">
      <img class="d-block w-100" src="..." alt="Second slide">
    </div>

    <div class="carousel-item">
      <img class="d-block w-100" src="..." alt="Third slide">
    </div>
  </div>

  <a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
    <span class="carousel-control-prev-icon" aria-hidden="true"></span>
    <span class="sr-only">Previous</span>
  </a>

  <a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
    <span class="carousel-control-next-icon" aria-hidden="true"></span>
    <span class="sr-only">Next</span>
  </a>
</div>

因为你忘记在 img 标签的 src 属性 之后加上等号

<div id="carousel" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
  <li data-target="#carousel" data-slide-to="0" class="active"></li>
  <li data-target="#carousel" data-slide-to="1"></li>
  <li data-target="#carousel" data-slide-to="2"></li>
  <li data-target="#carousel" data-slide-to="3"></li>
</ol>
<div class="carousel-inner" role="listbox">
  <div class="item active">
    <img class="d-block img-fluid" src="{{ asset('img/key-visuals/01-lh.jpg') }}" alt="First slide">
  </div>
  <div class="item">
    <img class="d-block img-fluid" src="{{ asset('img/key-visuals/02-lx.jpg') }}" alt="Second slide">
  </div>
  <div class="item">
    <img class="d-block img-fluid" src="{{ asset('img/key-visuals/03-os.jpg') }}" alt="Third slide">
  </div>
  <div class="item">
    <img class="d-block img-fluid" src="{{ asset('img/key-visuals/04-sn.jpg') }}" alt="Fourth slide">
  </div>
</div>
<a class="carousel-control left" href="#carousel" data-slide="prev">
  <span class="icon-prev left"></span>
</a>

<a class="carousel-control right" href="#carousel" data-slide="next">
  <span class="icon-next right"></span>
</a>