【问题标题】:How to add a carousel as background in bootstrap4?如何在 bootstrap4 中添加轮播作为背景?
【发布时间】:2020-02-28 03:05:42
【问题描述】:

我正在使用bootstrap4 构建一个简单的网站,并且我正在尝试将轮播设置为背景。有没有没有关键帧的简单方法?

【问题讨论】:

    标签: php html css bootstrap-4 carousel


    【解决方案1】:

    您可以使用引导默认轮播并进行一些调整,即 z-index 和 position 属性。

    图片1、2、3必须换成你自己的图片,没有它们就不行而且尺寸适合你的需要,你还可以为图片和箭头添加指示符循环浏览图像。

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <title>Bootstrap Carousel 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.4.1/css/bootstrap.min.css">
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
      <style>
      /* Make the image fully responsive */
      .carousel-inner img {
        width: 100%;
        height: 100%;
      }
    
      #demo{
        position: absolute;
        z-index: -1;
      }
    
      #frontpage{
        color: red; 
        font-size: larger;
        background-color: yellow;
        opacity: 0.5;
        padding: 50px;
      }
      </style>
    </head>
    <body>
    
    <div id="demo" class="carousel slide" data-ride="carousel">
    
      <!-- The slideshow -->
      <div class="carousel-inner">
        <div class="carousel-item active">
          <img src="Image1.jpg" alt="Image1" width="1920" height="1080">
        </div>
        <div class="carousel-item">
          <img src="Image2.jpg" alt="Image2" width="1920" height="1080">
        </div>
        <div class="carousel-item">
          <img src="Image3.jpg" alt="Image3" width="1920" height="1080">
        </div>
      </div>
    
    </div>
    <div id="frontpage">
    My frontpage over the carousel
    </div>
    
    </body>
    </html>
    

    【讨论】:

    • 谢谢,它看起来不错,但是如果我将首页的高度设置为 1000px,那么首页的框就会比轮播中的图像大
    • @pankan,很高兴为您提供帮助,您可以根据自己的意愿调整尺寸。您可以调整carousel-inner img的宽度和高度,并调整图像的宽度和高度。
    • @pankan,例如,您可以使用.carousel-inner img { width: 1500px; height: 1000px; }。您现在必须根据需要对其进行调整,并且可以编辑图像以使其不变形。
    • 如果我在 css 中设置了你建议的内容,那么图像将不再响应
    • @pankan,这很奇怪,刚刚对其进行了测试并且工作正常,确保样式表已正确链接和加载,这里有一些线程列出了样式表无法像这样工作的原因:@987654321 @
    猜你喜欢
    • 1970-01-01
    • 2013-10-28
    • 2019-12-21
    • 1970-01-01
    • 1970-01-01
    • 2021-08-20
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    相关资源
    最近更新 更多