Bootstrap 3 网格轮播

Posted

技术标签:

【中文标题】Bootstrap 3 网格轮播【英文标题】:Bootstrap 3 Grid Carousel 【发布时间】:2016-11-24 08:28:22 【问题描述】:

我正在尝试制作一个带有多个网格元素的轮播。我想用 Bootstrap 3 来做这个,但我做不到。

这就是我想要的轮播。 Carousel showing a grid system rather than a single image

哪位专家可以帮助我?

【问题讨论】:

尝试在item内使用带有class行的div,应该可以正常使用grid 我过去曾这样做过,将轮播内容设为一行,或者在本例中为一个包含多个单元格的表格。 【参考方案1】:

我认为最简单的方法是使用每个轮播项目作为基于单元格的内容的容器。在这种情况下,我使用一张表格来保存一些图像,但也可以使用引导行。

td 
  background-image: url(http://lorempixel.com/72/72/);
  background-size: cover;
  background-position: center center;
  width: 33%;
  height: 100px;
  border: solid 2px aliceblue;
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">

<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">

  <!-- Indicators -->
  <ol class="carousel-indicators">
    <li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
    <li data-target="#carousel-example-generic" data-slide-to="1"></li>
    <li data-target="#carousel-example-generic" data-slide-to="2"></li>
  </ol>

  <!-- Wrapper for slides -->
  <div class="carousel-inner" role="listbox">
    <div class="item active">
      <table style="width: 100%;">
        <tr><td></td><td rowspan="2"></td><td></td></tr>
        <tr><td></td><td></td></tr>
      </table>
    </div>

    <div class="item">
      <table style="width: 100%;">
        <tr><td rowspan="2"></td><td></td><td rowspan="2"></td></tr>
        <tr><td></td></tr>
      </table>
    </div>

    <div class="item">
      <table style="width: 100%;">
        <tr><td></td><td></td><td></td></tr>
        <tr><td></td><td></td><td></td></tr>
      </table>
    </div>

  </div>

  <!-- Controls -->
  <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
    <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
    <span class="sr-only">Previous</span>
  </a>
  <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
    <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
    <span class="sr-only">Next</span>
  </a>
</div>


<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>

【讨论】:

【参考方案2】:

td 
  background-image: url(http://lorempixel.com/72/72/);
  background-size: cover;
  background-position: center center;
  width: 33%;
  height: 100px;
  border: solid 2px aliceblue;
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">

<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">

  <!-- Indicators -->
  <ol class="carousel-indicators">
    <li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
    <li data-target="#carousel-example-generic" data-slide-to="1"></li>
    <li data-target="#carousel-example-generic" data-slide-to="2"></li>
  </ol>

  <!-- Wrapper for slides -->
  <div class="carousel-inner" role="listbox">
    <div class="item active">
      <table style="width: 100%;">
        <tr><td></td><td rowspan="2"></td><td></td></tr>
        <tr><td></td><td></td></tr>
      </table>
    </div>

    <div class="item">
      <table style="width: 100%;">
        <tr><td rowspan="2"></td><td></td><td rowspan="2"></td></tr>
        <tr><td></td></tr>
      </table>
    </div>

    <div class="item">
      <table style="width: 100%;">
        <tr><td></td><td></td><td></td></tr>
        <tr><td></td><td></td><td></td></tr>
      </table>
    </div>

  </div>

  <!-- Controls -->
  <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
    <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
    <span class="sr-only">Previous</span>
  </a>
  <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
    <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
    <span class="sr-only">Next</span>
  </a>
</div>


<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>

【讨论】:

以上是关于Bootstrap 3 网格轮播的主要内容,如果未能解决你的问题,请参考以下文章

前端Bootstrap案例:网格系统鼠标悬浮动画显示响应式布局

Bootstrap 3轮播不工作

Bootstrap 3.0 中带有缩略图的轮播

Bootstrap框架常用组件

Bootstrap 3轮播过渡速度

如何在 Bootstrap 中制作超过 3 张图像的轮播?