【问题标题】:Placing a jumbotron over a carousel in Bootstrap在 Bootstrap 中将 jumbotron 放置在旋转木马上
【发布时间】:2021-01-26 05:03:33
【问题描述】:

我正在尝试在 Bootstrap 5 中简单地将 jumbotron 放在轮播顶部。

我想出了一个解决办法,但由于某种原因,我的 Jumbotron 没有覆盖轮播。

这里的目标是在轮播通过其后面的幻灯片时,在顶部放置一个带有两个活动按钮的静态消息。任何建议将不胜感激。

<!-- Jumbo Tron -->
      <div class="jumbotron bg-light">
        <h1 class="display-4">Hello, world!</h1>
        <p class="lead">This is a simple hero unit, a simple jumbotron-style component for calling extra attention to featured content or information.</p>
        <hr class="my-4">
        <p>It uses utility classes for typography and spacing to space content out within the larger container.</p>
        <p class="lead">
          <a class="btn btn-primary btn-lg" href="#" role="button">KVLF The Voice of the Big Bend</a>
          <a class="btn btn-primary btn-lg" href="#" role="button">KALP Big Bend Country</a>
        </p>
      </div>


      <!-- Carousel -->
      <div id="carouselExampleIndicators" class="carousel slide" data-bs-ride="carousel">
        <ol class="carousel-indicators">
          <li data-bs-target="#carouselExampleIndicators" data-bs-slide-to="0" class="active"></li>
          <li data-bs-target="#carouselExampleIndicators" data-bs-slide-to="1"></li>
          <li data-bs-target="#carouselExampleIndicators" data-bs-slide-to="2"></li>
        </ol>
        <div class="carousel-inner">
          <div class="carousel-item active">
            <img src="img/Wstorefront.jpg" class="d-block w-100" alt="...">
          </div>
          <div class="carousel-item">
            <img src="img/Wsocks1.jpg" class="d-block w-100" alt="...">
          </div>
          <div class="carousel-item">
            <img src="img/Wstoreinterior1.jpg" class="d-block w-100" alt="...">
          </div>
        </div>
        <a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-bs-slide="prev">
          <span class="carousel-control-prev-icon" aria-hidden="true"></span>
          <span class="visually-hidden">Previous</span>
        </a>
        <a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-bs-slide="next">
          <span class="carousel-control-next-icon" aria-hidden="true"></span>
          <span class="visually-hidden">Next</span>
        </a>
      </div>




</div>

【问题讨论】:

    标签: html css carousel bootstrap-5


    【解决方案1】:

    如果您的目标是添加轮播滑块并在轮播顶部设置一些内容,例如按钮、文本等。

    这是一个带有自定义内容的轮播滑块示例

    <!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/3.4.1/css/bootstrap.min.css">
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
    </head>
    <body>
    
    <div class="container">
      <h2>Carousel Example</h2>
      <div id="myCarousel" class="carousel slide" data-ride="carousel">
        <!-- Custom content on top -->
        <div style="
        position: absolute;
        bottom: 20%;
        left: 50%;
        right: auto;
        align-items: center;
        z-index: 99;
        text-align: center;
    "><button>Show More</button><p style="
        color: white;
    ">Static contant</p></div>
        <!-- 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/chicago.jpg" alt="Los Angeles" style="width:100%;">
            <div class="carousel-caption">
              
            </div>
          </div>
    
          <div class="item">
            <img src="https://www.w3schools.com/bootstrap/ny.jpg" alt="Chicago" style="width:100%;">
            <div class="carousel-caption">
              
            </div>
          </div>
        
          <div class="item">
            <img src="https://www.w3schools.com/bootstrap/chicago.jpg" alt="New York" style="width:100%;">
            <div class="carousel-caption">
             
            </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>
    </div>
    
    </body>
    </html>

    【讨论】:

    • 我很感激,我只是想在一个滑动轮播的顶部添加一个按钮和文本,随着图片的变化,它不会移动。理想情况下,我希望文本和按钮保持静止,而在所述文本后面有幻灯片移动。非常感谢您的反馈,这对我继续学习 Bootstraping 世界非常有用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多