Isaac Isaac - 10 days ago 5
CSS Question

When does css file retrieve background-img URL?

When a .css file uses a url for an image file, does the client retrieve that image when the .css file is loaded or does it wait until the specific class is assigned to an element?

For example -

A user loads home.html with style.css referenced in the header. The home page does not include any elements with class

attach_background_image
, but within style.css we have

.attach_background_image{
background-image:URL(background.png);
}


Will background.png be retrieved when home.html is hit? Or does the image only get requested when an element meets the css selector criteria?

Answer

it will be retrieved on page load, when the class .attach_background_image is loaded