Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

Bootstrap 5 轮播


轮播 / 幻灯片

轮播是一种用于循环显示元素的幻灯片。


如何创建轮播

以下示例展示了如何创建带有指示器和控制按钮的基本轮播。

示例

<!-- 轮播 -->
<div id="demo" class="carousel slide" data-bs-ride="carousel">

  <!-- 指示器/点 -->
  <div class="carousel-indicators">
    <button type="button" data-bs-target="#demo" data-bs-slide-to="0" class="active"></button>
    <button type="button" data-bs-target="#demo" data-bs-slide-to="1"></button>
    <button type="button" data-bs-target="#demo" data-bs-slide-to="2"></button>
  </div>

  <!-- 幻灯片/轮播 -->
  <div class="carousel-inner">
    <div class="carousel-item active">
      <img src="la.jpg" alt="洛杉矶" class="d-block w-100">
    </div>
    <div class="carousel-item">
      <img src="chicago.jpg" alt="芝加哥" class="d-block w-100">
    </div>
    <div class="carousel-item">
      <img src="ny.jpg" alt="纽约" class="d-block w-100">
    </div>
  </div>

  <!-- 左右控制/图标 -->
  <button class="carousel-control-prev" type="button" data-bs-target="#demo" data-bs-slide="prev">
    <span class="carousel-control-prev-icon"></span>
  </button>
  <button class="carousel-control-next" type="button" data-bs-target="#demo" data-bs-slide="next">
    <span class="carousel-control-next-icon"></span>
  </button>
</div>
亲自试一试 »

示例解释

上面示例中每个类别的描述

类别 描述
.carousel 创建轮播
.carousel-indicators 为轮播添加指示器。这些指示器是每个幻灯片底部的小圆点(指示轮播中有多少幻灯片以及用户当前正在查看哪个幻灯片)。
.carousel-inner 为轮播添加幻灯片
.carousel-item 指定每个幻灯片的内容
.carousel-control-prev 为轮播添加一个左(上一个)按钮,允许用户在幻灯片之间后退
.carousel-control-next 为轮播添加一个右(下一个)按钮,允许用户在幻灯片之间前进
.carousel-control-prev-icon 与 .carousel-control-prev 一起使用以创建一个“上一个”按钮
.carousel-control-next-icon 与 .carousel-control-next 一起使用以创建一个“下一个”按钮
.slide 在从一个项目滑动到下一个项目时添加 CSS 过渡和动画效果。如果您不想要此效果,请删除此类。


向幻灯片添加标题


在每个 <div class="carousel-item"> 中的 <div class="carousel-caption"> 内添加元素以创建每个幻灯片的标题

示例

<div class="carousel-item">
  <img src="la.jpg" alt="洛杉矶">
  <div class="carousel-caption">
    <h3>洛杉矶</h3>
    <p>我们在洛杉矶玩得很开心!</p>
  </div>
</div>
亲自试一试 »


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.