我要创建两个彼此相邻的轮播

时间:2018-08-10 08:13:13

标签: javascript html css bootstrap-4 carousel

如何创建彼此相邻的两个轮播?

enter image description here

<div class="row">
    <div class="col-md-2"></div>
    <div class="col-md-8">
        <div id="Carousel" class="carousel slide">

            <ol class="carousel-indicators">
                <li data-target="#Carousel" data-slide-to="0" class="active"></li>
                <li data-target="#Carousel" data-slide-to="1"></li>
            </ol>

            <!-- Carousel items -->
            <div class="carousel-inner">

                <div class="item active">
                    <div class="row">
                        <div class="col-md-6"><a href="images/one.jpeg" target="_blank" class="thumbnail"><img src="images/two.jpeg" class="img-responsive" alt="Image" style="max-width:100%;"></a></div>
                        <div class="col-md-6"><a href="https://a2ua.com/picture/picture-002.jpg" target="_blank" class="thumbnail"><img src="https://a2ua.com/picture/picture-002.jpg" alt="Image" style="max-width:100%;"></a></div>
                    </div><!--.row-->
                </div><!--.item-->

                <div class="item">
                    <div class="row">
                        <div class="col-md-6"><a href="https://a2ua.com/picture/picture-002.jpg" target="_blank" class="thumbnail"><img src="https://a2ua.com/picture/picture-002.jpg" class="img-responsive" alt="Image" alt="Image" style="max-width:100%;"></a></div>
                        <div class="col-md-6"><a href="https://a2ua.com/picture/picture-002.jpg" target="_blank" class="thumbnail"><img src="https://a2ua.com/picture/picture-002.jpg" class="img-responsive" alt="Image" style="max-width:100%;"></a></div>
                    </div><!--.row-->
                </div><!--.item-->

            </div><!--.carousel-inner-->

            <a data-slide="prev" href="#Carousel" class="left carousel-control black-link">‹</a>
            <a data-slide="next" href="#Carousel" class="right carousel-control black-link">›</a>

        </div><!--.Carousel-->

    </div> <!--.col-md-8-->
</div> <!--.row-->

<div class="row">
    <div class="col-md-2"></div>
    <div class="col-md-8">
        <div id="Carousel2" class="carousel slide">

            <ol class="carousel-indicators">
                <li data-target="#Carousel" data-slide-to="0" class="active"></li>
                <li data-target="#Carousel" data-slide-to="1"></li>
            </ol>

            <!-- Carousel items -->
            <div class="carousel-inner">

                <div class="item active">
                    <div class="row">
                        <div class="col-md-6"><a href="images/one.jpeg" target="_blank" class="thumbnail"><img src="images/two.jpeg" class="img-responsive" alt="Image" style="max-width:100%;"></a></div>
                        <div class="col-md-6"><a href="https://a2ua.com/picture/picture-002.jpg" target="_blank" class="thumbnail"><img src="https://a2ua.com/picture/picture-002.jpg" alt="Image" style="max-width:100%;"></a></div>
                    </div><!--.row-->
                </div><!--.item-->

                <div class="item">
                    <div class="row">
                        <div class="col-md-6"><a href="https://a2ua.com/picture/picture-002.jpg" target="_blank" class="thumbnail"><img src="https://a2ua.com/picture/picture-002.jpg" class="img-responsive" alt="Image" alt="Image" style="max-width:100%;"></a></div>
                        <div class="col-md-6"><a href="https://a2ua.com/picture/picture-002.jpg" target="_blank" class="thumbnail"><img src="https://a2ua.com/picture/picture-002.jpg" class="img-responsive" alt="Image" style="max-width:100%;"></a></div>
                    </div><!--.row-->
                </div><!--.item-->

            </div><!--.carousel-inner-->

            <a data-slide="prev" href="#Carousel" class="left carousel-control black-link">‹</a>
            <a data-slide="next" href="#Carousel" class="right carousel-control black-link">›</a>

        </div><!--.Carousel-->

    </div> <!--.col-md-8-->
</div> <!--.row-->

and maybe I choose incorrect word to search

1 个答案:

答案 0 :(得分:0)

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
</head>
<body>
<div class="row">
<div class="col">
<div id="carouselExampleSlidesOnly" class="carousel slide" data-ride="carousel">
  <div class="carousel-inner">
    <div class="carousel-item active">
      <img class="d-block w-100" src="https://placeimg.com/640/480/any" alt="First slide">
    </div>
    <div class="carousel-item">
      <img class="d-block w-100" src="https://placeimg.com/640/480/any" alt="Second slide">
    </div>
    <div class="carousel-item">
      <img class="d-block w-100" src="https://placeimg.com/640/480/any" alt="Third slide">
    </div>
  </div>
</div>
</div>
<div class="col">
<div id="carouselExampleSlidesOnly" class="carousel slide" data-ride="carousel">
  <div class="carousel-inner">
    <div class="carousel-item active">
      <img class="d-block w-100" src="https://placeimg.com/640/480/any" alt="First slide">
    </div>
    <div class="carousel-item">
      <img class="d-block w-100" src="https://placeimg.com/640/480/any" alt="Second slide">
    </div>
    <div class="carousel-item">
      <img class="d-block w-100" src="https://placeimg.com/640/480/any" alt="Third slide">
    </div>
  </div>
</div>
</div>
</div>
</body>
</html>

只需将col值调整为col-2或col-3等,即可获得所需的结果