Overriding CSS background image styles - both images are loaded?

后端 未结 4 731
孤城傲影
孤城傲影 2021-01-11 13:40

If I have 2 CSS styles that assign background images to an element, and one style overrides the other. Will both images be downloaded by the browser or just the overriding o

4条回答
  •  旧时难觅i
    2021-01-11 14:17

    The overridden image will not be loaded.

    Just to be clear, for example: http://jsfiddle.net/thirtydot/MjKfG/1/show/

    test
    div { background: url(http://dummyimage.com/600x400/000/fff) } #test { background: url(http://dummyimage.com/200); width: 200px; height: 200px }

    Only http://dummyimage.com/200 will be loaded.

    This is true in at least Chrome, Safari, Firefox, IE8/9, Opera.

    I'd guess it's true in all browsers, because it's a simple and effective optimization.

提交回复
热议问题