Bootstrap轮播中的图像无法显示

时间:2016-12-21 14:44:15

标签: bootstrap-carousel

所以,我的图片不会显示在我的旋转木马中。我试过多次更改名称,没有任何反应。我甚至把图像放到了img文件夹中。我顺便使用了灰度模板。有人可以解释一下吗?

<div class="container">
  <br>
  <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>
      <li data-target="#myCarousel" data-slide-to="3"></li>
    </ol>

    <!-- Wrapper for slides -->
    <div class="carousel-inner" role="listbox">
      <div class="item active">
        <img src="store" alt="store" width="460" height="345">
      </div>

      <div class="item">
        <img src="art.jpg" alt="art" width="460" height="345">
      </div>

      <div class="item">
        <img src=".jpg" alt="Flower" width="460" height="345">
      </div>

      <div class="item">
        <img src="img_flower2.jpg" alt="Flower" width="460" height="345">
      </div>
    </div>

    <!-- Left and right controls -->
    <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
      <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
      <span class="sr-only">Previous</span>
    </a>
    <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
      <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
      <span class="sr-only">Next</span>
    </a>
  </div>
</div>

2 个答案:

答案 0 :(得分:1)

这里有多个问题:

  1. 查看the carousel example后,包装器下的容器(即<div class="carousel-inner" role="listbox">)似乎缺少类 carousel-item

    <div class="item">
        <img src="art.jpg" alt="art" width="460" height="345">`
    

    所以添加该类名:

    <div class="item carousel-item">
        <img src="art.jpg" alt="art" width="460" height="345">`
    
  2. 图片代码的某些源属性似乎包含无效的文件名 - 例如<img src="store" alt="store" width="460" height="345">

  3. 除非你不想要它们(也许你有不同的图标),下一个和前一个图标容器缺少类 icon-prev icon-next <span class="glyphicon glyphicon-chevron-left icon-prev" aria-hidden="true"></span>
  4. 此外,您可能已经这样做了,但确保添加了所需的CSS和JS文件(请参阅Quick start部分)。
  5. <link href="https://v4-alpha.getbootstrap.com/assets/css/docs.min.css" rel="stylesheet"/>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/css/bootstrap.min.css" integrity="sha384-AysaV+vQoT3kOAXZkl02PThvDr8HYKPZhNT5h/CXfBThSRXQ6jW5DO2ekP5ViFdi" crossorigin="anonymous">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js" integrity="sha384-3ceskX3iaEnIogmQchP8opvBy3Mi7Ce34nWjpBIwVTHfGYWQS9jwHDVRnpKKHJg7" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.3.7/js/tether.min.js" integrity="sha384-XTs3FgkjiBgo8qjEjBk0tGmf3wPrWtA6coPfQDfFEY8AnYJwjalXCiosYRBIBZX8" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.5/js/bootstrap.min.js" integrity="sha384-BLiI7JTZm+JWlgKa0M0kGRpJbF2J8q+qreVrKBC47e3K6BW78kGLrCkeRX6I9RoK" crossorigin="anonymous"></script>
    <div class="container">
      <br>
      <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>
          <li data-target="#myCarousel" data-slide-to="3"></li>
        </ol>
    
        <!-- Wrapper for slides -->
        <div class="carousel-inner" role="listbox">
          <div class="carousel-item active">
            <img src="https://lh5.googleusercontent.com/-H-d48F21u4Y/AAAAAAAAAAI/AAAAAAAAABU/axGFMUf4bwY/photo.jpg?sz=32" alt="store" width="64" height="64">
          </div>
    
          <div class="carousel-item">
            <img src="https://i.stack.imgur.com/C92ci.png?s=64&g=1" alt="art" width="64" height="64">
          </div>
    
          <div class="carousel-item">
            <img src="https://www.gravatar.com/avatar/fd047157030a440fa1f62e6e1ed87958?s=32&d=identicon&r=PG" alt="Flower" width="64" height="64">
          </div>
    
          <div class="carousel-item">
            <img src="https://www.gravatar.com/avatar/fa3b74688aaf69a2d65fd846b0a82c59?s=32&d=identicon&r=PG&f=1" alt="Flower" width="64" height="64">
          </div>
        </div>
    
        <!-- Left and right controls -->
        <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
          <span class="glyphicon glyphicon-chevron-left icon-prev" aria-hidden="true"></span>
          <span class="sr-only">Previous</span>
        </a>
        <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
          <span class="glyphicon glyphicon-chevron-right icon-next" aria-hidden="true"></span>
          <span class="sr-only">Next</span>
        </a>
      </div>
    </div>

答案 1 :(得分:0)

您的代码显示某些图片src属性没有扩展名,有些没有名称和扩展名。您的src属性也一定存在问题,因为您可能没有放置正确的图像路径。

<img src="store" alt="store" width="460" height="345">
<img src=".jpg" alt="Flower" width="460" height="345">