【问题标题】:Bootstrap carousel caption引导轮播标题
【发布时间】:2018-04-20 23:00:31
【问题描述】:

我正在使用以下代码实现轮播。在这个我想要两个标题按照轮播幻灯片。因此,我将再添加一个标题 div,但它无法正常工作。我需要一个标题用于旋转木马的左上角,另一个标题用于旋转木马的底部。我不知道 css,所以请帮助任何人。

<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
  <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
  <li data-target="#myCarousel" data-slide-to="1"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner">
  <div class="item active">
    <img src="la.jpg" alt="Los Angeles" style="width:100%;">
    <div class="carousel-caption">
      <h3>Los Angeles</h3>
      <p>LA is always so much fun!</p>
    </div>
  </div>
  <div class="item">
    <img src="chicago.jpg" alt="Chicago" style="width:100%;">
    <div class="carousel-caption">
      <h3>Chicago</h3>
      <p>Thank you, Chicago!</p>
    </div>
  </div>
</div>
<!-- Left and right controls -->
<a class="left carousel-control" href="#myCarousel" data-slide="prev">
  <span class="glyphicon glyphicon-chevron-left"></span>
  <span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" data-slide="next">
  <span class="glyphicon glyphicon-chevron-right"></span>
  <span class="sr-only">Next</span>
</a>

【问题讨论】:

  • 我不明白你的意思。但你可以在jsfiddle.net/devefrontend/21036h5c/8 中举个例子
  • 感谢您的回复。例如,我希望

    标记内的文本位于轮播的左上角,而

    标记中的文本位于轮播的中心

标签: javascript jquery html css twitter-bootstrap


【解决方案1】:

也许这会有所帮助。

例如这里>https://jsfiddle.net/devefrontend/21036h5c/10/

  <div class="carousel-caption">
    <h3 class="text-right">Los Angeles</h3>
    <p  class="text-right">LA is always so much fun!</p>
  </div>

和css

.carousel-caption {
  width:100%;
  height:100%;
  left:0;
  padding: 50px;
}

【讨论】:

    【解决方案2】:

    我认为下面的示例会对您有所帮助,

    将标题设为 100% 宽度和高度,并覆盖 h3 和 p 文本的一些属性(针对不同视图使用媒体查询)

    .carousel-caption {
        width:100%;
        height:100%;
        left:0 !important;
    }
    
    .carousel-caption h3 {
      text-align:left;
      margin-left:30px;
    }
    .carousel-caption p {
      margin-top:40%;
    }
    @media screen and (max-width: 479px) {
      .carousel-caption p {
        margin-top:20%;
      }
    }
    
    @media screen and (min-width: 480px) and (max-width: 640px){
      .carousel-caption p {
        margin-top:30%;
      }
    }
    
    @media screen and (min-width: 641px) {
      .carousel-caption p {
        margin-top:40%;
      }
    }
    <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.7/js/bootstrap.min.js"></script>
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
    <div id="myCarousel" class="carousel slide" data-ride="carousel">
      <!-- Indicators -->
      <ol class="carousel-indicators">
        <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
        <li data-target="#myCarousel" data-slide-to="1"></li>
        <li data-target="#myCarousel" data-slide-to="2"></li>
      </ol>
    
      <!-- Wrapper for slides -->
      <div class="carousel-inner">
        <div class="item active">
          <img src="https://www.w3schools.com/bootstrap/la.jpg" alt="Los Angeles">
          <div class="carousel-caption">
            <h3>Los Angeles</h3>
            <p>LA is always so much fun!</p>
          </div>
        </div>
    
        <div class="item">
          <img src="https://www.w3schools.com/bootstrap/chicago.jpg" alt="Chicago">
          <div class="carousel-caption">
            <h3>Chicago</h3>
            <p>Thank you, Chicago!</p>
          </div>
        </div>
    
        <div class="item">
          <img src="https://www.w3schools.com/bootstrap/ny.jpg" alt="New York">
          <div class="carousel-caption">
            <h3>New York</h3>
            <p>We love the Big Apple!</p>
          </div>
        </div>
      </div>
    
      <!-- Left and right controls -->
      <a class="left carousel-control" href="#myCarousel" data-slide="prev">
        <span class="glyphicon glyphicon-chevron-left"></span>
        <span class="sr-only">Previous</span>
      </a>
      <a class="right carousel-control" href="#myCarousel" data-slide="next">
        <span class="glyphicon glyphicon-chevron-right"></span>
        <span class="sr-only">Next</span>
      </a>
    </div>

    【讨论】:

    • 不客气 :)
    【解决方案3】:

    这部分是我所需要和帮助的。

    .carousel-caption {
        width:100%;
        height:100%;
        left:0 !important;
    }
    
    .carousel-caption h3 {
      text-align:left;
      margin-left:30px;
    }
    .carousel-caption p {
      margin-top:40%;
    }
    @media screen and (max-width: 479px) {
      .carousel-caption p {
        margin-top:20%;
      }
    }
    
    @media screen and (min-width: 480px) and (max-width: 640px){
      .carousel-caption p {
        margin-top:30%;
      }
    }
    
    @media screen and (min-width: 641px) {
      .carousel-caption p {
        margin-top:40%;
      }
    }
    

    【讨论】:

    猜你喜欢
    • 2015-04-02
    • 2017-04-11
    • 1970-01-01
    • 1970-01-01
    • 2016-08-31
    • 2023-03-05
    相关资源
    最近更新 更多