admin管理员组

文章数量:1328037

How can one define multiple background images in CSS3 programmatically via JavaScript?

The obvious idea:

var element = document.createElement( 'div' );
element.style.backgroundImage = "url('a.png') 0 100%, url('b.png') 50px 50px ";

doesn't work - it must be something simple, but what?

How can one define multiple background images in CSS3 programmatically via JavaScript?

The obvious idea:

var element = document.createElement( 'div' );
element.style.backgroundImage = "url('a.png') 0 100%, url('b.png') 50px 50px ";

doesn't work - it must be something simple, but what?

Share Improve this question asked Mar 9, 2013 at 23:38 qdotqdot 6,3455 gold badges45 silver badges100 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 9

backgroundImage is for background image only if you are setting multiple background properties in one you have to use background.

element.style.background = "url('a.png') 0 100%, url('b.png') 50px 50px ";

本文标签: cssCSS3 multiple background images from JavaScriptStack Overflow