Twitter bootstrap 卡中的数据源无法正常工作

Twitter bootstrap data-src in card not working

根据 twitter bootstrap 网站上给出的 example,以下代码

<div class="card">
  <img class="card-img-top" data-src="holder.js/100%x180/" alt="Card image cap">
  <div class="card-block">
    <h4 class="card-title">Card title</h4>
    <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
    <a href="#" class="btn btn-primary">Button</a>
  </div>
</div>

应该会产生一张不错的卡片,但它会产生

谁能告诉我问题出在哪里? 似乎数据属性对我不起作用。

您从中获取代码的示例使用的是 holder.js,但 Bootstrap 分发版实际上并未附带 holder.js。您的 data-src 属性引用了一个不存在的文件。

如果您需要占位符图片,您可以:

如果您使用常规图片,请记住您必须使用常规源属性:

<img class="card-img-top" src="http://placehold.it/350x150" alt="Card image cap">

我认为@bsmp 的回答是正确的。

Holder 将处理所有具有特定 src 属性的图像,例如 src="holder.js/318x180",并自动生成图像源到 data-src 属性。

  1. 使用以下代码在您的页面中包含 holder:

    <script src="https://cdn.jsdelivr.net/holder/2.9.0/holder.min.js"> </script>

    您还可以在 https://github.com/imsky/holder

  2. 下载 holder.js
  3. 使用 img 元素的 src 属性来定义您的持有人图像:

    <img class="card-img-top" src="holder.js/318x180" alt="Card image cap"> <div class="card-block">

请注意,对于最新版本的 holder.js

,您不必在 src 属性中转义 holder 语法

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha/css/bootstrap.min.css" rel="stylesheet"/>

<div class="card" style="width:318px;">
  <img class="card-img-top" src="holder.js/318x180" alt="Card image cap">
  <div class="card-block">
<h4 class="card-title">Card title</h4>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
<a href="#" class="btn btn-primary">Button</a>
  </div>
</div>

 <script src="https://cdn.jsdelivr.net/holder/2.9.0/holder.min.js"></script>