简体   繁体   English

Bootstrap 4 Carousel组件问题

[英]Bootstrap 4 Carousel component Issue

I am trying to implement Carousel Bootstrap 4 to a personal project. 我正在尝试将Carousel Bootstrap 4实施到个人项目中。 I have basic understanding of HTML5, CSS3, Bootstrap 4 and JS. 我对HTML5,CSS3,Bootstrap 4和JS有基本的了解。 I have look to several discussions and tutorials on how to use the carousel component, but cannot get the correct output in the browser. 我已经看过关于如何使用轮播组件的一些讨论和教程,但是无法在浏览器中获得正确的输出。 I use chrome and firefox and have the same problem in both browsers. 我使用chrome和firefox,在两个浏览器中都存在相同的问题。 I already check the paths of (link) and (script) , I even had to change the (img data-src="#") to (img src="#") so the images could load properly into the browser. 我已经检查了(link)和(script)的路径,甚至不得不将(img data-src =“#”)更改为(img src =“#”),以便图像可以正确加载到浏览器中。 The images are on top of each other and don't know how to correct this problem. 图像彼此重叠,不知道如何解决此问题。 I copy the code directly from the Bootstrap website. 我直接从Bootstrap网站复制代码。 This is my first time in a community and my first question. 这是我第一次进入社区,也是我的第一个问题。 Just feeling a bit of frustration with this component. 对此组件感到有点沮丧。

Thanks in advance! 提前致谢!

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>

You need to put your HTML inside the <body> tag in order for it to render properly. 您需要将HTML放在<body>标记内,以使其正确呈现。

<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>

Change the class "carousel-item" to "item". 将类“ 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM