我的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,而不是第一张图片,但没有其他图片。等等..
有什么想法?
,因为您忘记将src
属性等于 img
tag
<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>
您正在使用Bootstrap 4,但仍依靠过时的Bootstrap 3类名称。item
应为Bootstrap的更新指南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>