【问题标题】:Bootstrap 4 Carousel component IssueBootstrap 4轮播组件问题
【发布时间】:2016-04-14 04:01:55
【问题描述】:

我正在尝试将 Carousel Bootstrap 4 实施到个人项目中。我对 HTML5、CSS3、Bootstrap 4 和 JS 有基本的了解。我看过几个关于如何使用轮播组件的讨论和教程,但无法在浏览器中获得正确的输出。我使用 chrome 和 firefox 并且在两个浏览器中都有同样的问题。我已经检查了 (link) 和 (script) 的路径,我什至不得不将 (img data-src="#") 更改为 (img src="#") 以便图像可以正确加载到浏览器中。这些图像相互重叠,不知道如何解决这个问题。我直接从 Bootstrap 网站复制代码。这是我第一次进入社区,也是我的第一个问题。只是对这个组件感到有点沮丧。

提前致谢!

Image example of problem in browser

    <!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">

  <title>Carousel-testing!</title>
  <link rel="stylesheet" href="assets\css\bootstrap.css">
  <link rel="stylesheet" href="assets\css\bootstrap-theme.css">
  <link rel="stylesheet" href="assets\css\app.css">
  <link rel="stylesheet" href="assets\css\animate.css">

  <script type="text/javascript" src="assets\js\jquery.js"></script>
  <script type="text/javascript" src="assets\js\bootstrap.js"></script>
  <script type="text/javascript" src="assets\js\app.js"></script>
</head>

<nav>

</nav>

<section id="carousel">

  <div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
    <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>
    <div class="carousel-inner" role="listbox">
      <div class="carousel-item active">
        <img src="assets\images\2736779-casino-roulette-in-water-and-fire-isolated-on-black-background.jpg" alt="First slide">
      </div>
      <div class="carousel-item">
        <img src="assets\images\DealerBust.jpg" alt="Second slide">
      </div>
      <div class="carousel-item">
        <img src="assets\images\FH_Gaming_Main-new.jpg" alt="Third slide">
      </div>
    </div>
    <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
      <span class="icon-prev" 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="icon-next" aria-hidden="true"></span>
      <span class="sr-only">Next</span>
    </a>
  </div>
</section>

<body>


</body>

</html>

【问题讨论】:

    标签: javascript jquery html css twitter-bootstrap


    【解决方案1】:

    您需要将您的 HTML 放入 &lt;body&gt; 标记中才能正确呈现。

    <body>
    <nav>
    
    </nav>
    
    <section id="carousel">
    
      <div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
        <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>
        <div class="carousel-inner" role="listbox">
          <div class="carousel-item active">
            <img src="assets\images\2736779-casino-roulette-in-water-and-fire-isolated-on-black-background.jpg" alt="First slide">
          </div>
          <div class="carousel-item">
            <img src="assets\images\DealerBust.jpg" alt="Second slide">
          </div>
          <div class="carousel-item">
            <img src="assets\images\FH_Gaming_Main-new.jpg" alt="Third slide">
          </div>
        </div>
        <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
          <span class="icon-prev" 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="icon-next" aria-hidden="true"></span>
          <span class="sr-only">Next</span>
        </a>
      </div>
    </section>
    </body>
    
    </html>
    

    【讨论】:

    • 好的,我把html放在body标签里面。仍然无法使用轮播组件。
    • 控制台中是否出现错误?尝试将 Bootstrap 和 app JS 脚本标签移动到正文的底部。
    • 是的,控制台告诉我bootstrap.js里面的第441行有一个错误朋友告诉我下载所有的bootstrap文件并从头开始。现在一切正常,不知道是什么导致了错误,但这似乎可以解决问题。感谢您的及时回复!
    【解决方案2】:

    将类“carousel-item”更改为“item”。

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    
    <title>Carousel-testing!</title>
    <link rel="stylesheet" href="assets\css\bootstrap.css">
    <link rel="stylesheet" href="assets\css\bootstrap-theme.css">
    <link rel="stylesheet" href="assets\css\app.css">
    <link rel="stylesheet" href="assets\css\animate.css">
    
    <script type="text/javascript" src="assets\js\jquery.js"></script>
    <script type="text/javascript" src="assets\js\bootstrap.js"></script>
    <script type="text/javascript" src="assets\js\app.js"></script>
    </head>
    
    <nav>
    
    </nav>
    
    <section id="carousel">
    
    <div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
    <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>
    <div class="carousel-inner" role="listbox">
      <div class="item active">
        <img src="assets\images\2736779-casino-roulette-in-water-and-fire-isolated-on-black-background.jpg" alt="First slide">
      </div>
      <div class="item">
        <img src="assets\images\DealerBust.jpg" alt="Second slide">
      </div>
      <div class="item">
        <img src="assets\images\FH_Gaming_Main-new.jpg" alt="Third slide">
      </div>
    </div>
    <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
      <span class="icon-prev" 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="icon-next" aria-hidden="true"></span>
      <span class="sr-only">Next</span>
    </a>
    </div>
    </section>
    

    【讨论】:

    • 在 Bootstrap 4 上,item 类已更改为 carousel-item。 v4-alpha.getbootstrap.com/components/carousel
    • 那是真正的拉贾特。我不得不再次下载引导程序,从头开始,现在它运行良好。不知道是什么错误,但现在它已修复。感谢您的及时回复!
    猜你喜欢
    • 1970-01-01
    • 2017-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多