Split Bootstrap4 Carousel-item in two

时间:2017-12-30 19:50:31

标签: jquery html css twitter-bootstrap carousel

嘿伙计们,我想将每张幻灯片分成两部分,一部分用于图片,一部分用于描述,请看图片。它是一个bootstrap 4,我没有找到任何解决方案,我只是找到了bootstrap 3的例子,这对我来说不起作用。

我使用了简单的网格<div class="col-lg-6">,但没有工作,只是在图片下推送了描述。

谢谢!

Picture - Something like this

<div id="demo" class="carousel slide" data-ride="carousel">
  <!-- The slideshow -->
  <div class="carousel-inner">
    <div class="carousel-item active">
        <div class="col-lg-6"> 
          <img src="http://lorempixel.com/400/200/" alt="Los Angeles" width="400" height="200">
        </div>
        <div class="col-lg-6"> 
          <h3>Firste caption</h3>
          <p>Loren ipsun</p>
        </div>
    </div>
    <div class="carousel-item ">
        <div class="col-lg-6"> 
          <img src="http://lorempixel.com/400/200/" alt="Los Angeles" width="400" height="200">
        </div>
        <div class="col-lg-6"> 
          <h3>Firste caption</h3>
          <p>Loren ipsun</p>
        </div>
    </div>
    <div class="carousel-item ">
        <div class="col-lg-6"> 
          <img src="http://lorempixel.com/400/200/" alt="Los Angeles" width="400" height="200">
        </div>
        <div class="col-lg-6"> 
          <h3>Firste caption</h3>
          <p>Loren ipsun</p>
        </div>
    </div>
  </div>
</div>

1 个答案:

答案 0 :(得分:0)

.row放在.carousel-item内,将.col-*放在.row内。像这样:

...
<div class="carousel-item ">
  <div class="row">
    <div class="col-lg-6"> 
      <img src="http://lorempixel.com/400/200/" alt="Los Angeles" width="400" height="200">
    </div>
    <div class="col-lg-6"> 
      <h3>Firste caption</h3>
      <p>Loren ipsun</p>
    </div>
  </div>
</div>
...

如果您希望轮播以较低的宽度保持分割,您可能希望将col-lg-6col-md-6col-sm-6col-6交换(在v4中表示它将在所有宽度上保持分裂。)

以下是一个例子:

&#13;
&#13;
.carousel-item {
  background-color: #424242;
  color: white;
  min-height: 220px;
}
&#13;
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css" rel="stylesheet"/>

<div id="carouselExample" class="carousel slide" data-ride="carousel">
  <div class="carousel-inner">
    <div class="carousel-item active">
      <div class="row">
        <div class="col-6">
          <img class="d-block w-100" src="http://lorempixel.com/304/220/" alt="First slide">
        </div>
        <div class="col-6 d-flex align-items-center">
          <div>
            <h2>Title</h2>
            <p>Lorem ipsum</p>
          </div>
        </div>
      </div>
    </div>
    <div class="carousel-item">
      <div class="row">
        <div class="col-6">
          <img class="d-block w-100" src="http://lorempixel.com/304/220/nightlife/" alt="Second slide">
        </div>
        <div class="col-6 d-flex align-items-center">
          <div>
            <h2>Title</h2>
            <p>Lorem ipsum</p>
          </div>
        </div>
      </div>
    </div>
    <div class="carousel-item">
      <div class="row">
        <div class="col-6">
          <img class="d-block w-100" src="http://lorempixel.com/304/220/sports/" alt="Third slide">
        </div>
        <div class="col-6 d-flex align-items-center">
         <div>
          <h2>Title</h2>
          <p>Lorem ipsum</p>
          </div>
        </div>
      </div>
    </div>
  
  <a class="carousel-control-prev" href="#carouselExample" 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="#carouselExample" role="button" data-slide="next">
    <span class="carousel-control-next-icon" aria-hidden="true"></span>
    <span class="sr-only">Next</span>
  </a>
</div>
&#13;
&#13;
&#13;