I have a class defined in my styles.css as:
.caquote {background: url("http://cdn.domain.com/images/quotebig.png") no-repeat 10px 8px ;}
Will the image still be loaded by modern browsers if on the html page I don't define .caquote
anywhere?
I have a class defined in my styles.css as:
.caquote {background: url("http://cdn.domain.com/images/quotebig.png") no-repeat 10px 8px ;}
Will the image still be loaded by modern browsers if on the html page I don't define .caquote
anywhere?
The images of a css are download only if they are used in the HTML : I have made an example for you in a jsfiddle : http://jsfiddle.net/b3QXu/ As you can see, the second image is load only when you hover the div. If you don't hover the div, the image will not be downloaded by your computer.
#bonjour {
background-image : url(http://rosalienebacchus.files.wordpress.com/2012/04/planet-earth-from-space.jpg);
width : 500px;
height : 500px;
background-color : #123456;
background-size : cover;
}
#bonjour:hover {
background-image : url(http://www.desktopas.com/files/2013/06/Outer-Space-Moon- Earth-Spaceman.jpg);
}
For your information : All images on a HTML file are load, even if they are set as display:none on css.
I don't see the two answers as contradictory. Damien says the background-image property that loads an image is invoked only when it's used. In his hover example, the image wasn't needed until the hover event.
cegfault says that the images are loaded even in a display:none. He also says that that the page can display (as enough elements are calculated and rendered), and then [once it has downloaded in parallel] the background image will appear. That doesn't mean that the bg image was blocked. Just that it was so big that it took a while to download.