3

按照 twitter bootstrap 网站上给出的示例,以下代码

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

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

在此处输入图像描述

谁能告诉问题可能是什么?似乎数据属性对我不起作用。

4

2 回答 2

2

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

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

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

<img class="card-img-top" src="http://placehold.it/350x150" alt="Card image cap">
于 2015-12-07T01:01:37.557 回答
1

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

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

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

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

    您也可以在https://github.com/imsky/holder下载 holder.js

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

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

请注意,您不必src为最新版本的 holder.js 转义属性中的 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>

于 2015-12-11T08:30:02.910 回答