Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Bootstrap 4 card images use data-src and not src for image tags?

In the demo code below it uses data-src but no img src. How is the image applied? Does the javascript modify this somehow?

http://v4-alpha.getbootstrap.com/components/card/

 <div class="card">
      <img class="card-img-top" data-src="..." 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>
like image 333
JacobLett Avatar asked Feb 03 '16 01:02

JacobLett


People also ask

What is the difference between data src and src?

src will render the value immediately and it's the default for images, videos using a single source and iframes. data-src is used when lazy loading to prevent the default image from loading when the page loads.

Does an IMG tag need a src?

The <img> tag has two required attributes: src - Specifies the path to the image. alt - Specifies an alternate text for the image, if the image for some reason cannot be displayed.

Why is the src attribute necessary in an IMG tag?

The required src attribute specifies the URL of the image. There are two ways to specify the URL in the src attribute: 1. Absolute URL - Links to an external image that is hosted on another website.

Why is img src not working?

Img src Not Working That means, when a web page loads, the browser has to retrieve the image from a web server and display it on the page. The broken link icon means that the browser could not find the image. If you've just added the image, then check that you included the correct image URL in the source attribute.


1 Answers

Bootstrap 4 documentation uses holder.js, see http://imsky.github.io/holder/

Also see: https://github.com/imsky/holder#usage

Include holder.js in your HTML:

Holder will then process all images with a specific src attribute, like this one:

The above tag will render as a placeholder 300 pixels wide and 200 pixels tall.

To avoid console 404 errors, you can use data-src instead of src.

Holder is included via http://v4-alpha.getbootstrap.com/assets/js/docs.min.js

like image 59
Bass Jobsen Avatar answered Sep 28 '22 04:09

Bass Jobsen