Bootstrap carousel仅显示第一张图像,即使它正在滑动到下一张图像

时间:2018-02-06 16:07:03

标签: html twitter-bootstrap symfony carousel bootstrap-carousel

我的bootstrap轮播包含4张图片。滑动/旋转木马本身工作正常,但不知何故只显示第一张图片,而滑动到图片2-4时,屏幕只滑动到白色空间,显示图像描述。

<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,该图片会显示但不会显示其他图片。等等..

有什么想法吗?

2 个答案:

答案 0 :(得分:1)

因为您忘记在src标记

img属性之后放置等于
<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>

答案 1 :(得分:0)

您使用的是Bootstrap 4,但仍然依赖于过时的Bootstrap 3类名。根据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>