Bootstrap Carousel-为什么我的图片没有显示?

时间:2017-10-24 00:50:59

标签: twitter-bootstrap carousel

我必须使用Bootstrap创建一个Carousel。我还是很新,所以我不太了解。我不明白为什么没有显示图像而只显示文本。我过去几个小时一直在寻找它,但仍然无法理解我做错了什么或失踪等等。我觉得我的头靠在墙上。任何人都可以帮助或任何信息将非常感激。

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Bootstrap 101 Template</title>
  <link href="css/bootstrap.min.css" rel="stylesheet">    
</head>

<body>
  <div id="Mycarousel" class="carousel">

    <ol class="carousel-indicators">
      <li class="item0" data-target="#Mycarousel" data-slide-to ="0" class="active"></li>
      <li class="item1" data-target="#Mycarousel" data-slide-to ="1"></li>
      <li class="item2"  data-target="#Mycarousel" data-slide-to ="2"></li>
    </ol>

    <div class="carousel-inner">
      <div class="item active">
        <img src="img/cars.jpg" alt="cars" class="img-responsive">
      </div>

      <div class="item"></div>
        <img src="img/waterflower.jpg" alt="waterflower" class="img-responsive">
      </div>

      <div class="item"></div>
        <img src="img/cutehedgehog.jpg" alt="cutehedgehog" class="img-responsive">
      </div>

      <a class="carousel-control" href="#Mycarousel" data-slide="prev"></a>
      <span class="icon-prev"></span>

      </div>
    </div>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.7/jquery.min.js"></script>
    <script src="js/bootstrap.js"></script>
  </body>
</html>

1 个答案:

答案 0 :(得分:0)

看起来你没有使脚手架正确。查看您为第二张和第三张幻灯片添加的额外结束"</div>"

<div class="item"></div>
 <img src="img/waterflower.jpg" alt="waterflower" class="img-responsive">
</div>

应该是这样的;

<div class="item">
 <img src="img/waterflower.jpg" alt="waterflower" class="img-responsive">
</div>

这是W3Schools提供的工作副本。

&#13;
&#13;
<!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.3.7/css/bootstrap.min.css">      
</head>
<body>

<div class="container">
  <h2>Carousel Example</h2>  
  <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" style="width:100%;">
      </div>

      <div class="item">
        <img src="https://www.w3schools.com/bootstrap/chicago.jpg" alt="Chicago" style="width:100%;">
      </div>
    
      <div class="item">
        <img src="https://www.w3schools.com/bootstrap/ny.jpg" alt="New york" style="width:100%;">
      </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>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>
&#13;
&#13;
&#13;