好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

求大神赐教,为什么我的图片背景background-image设置没有效果_html/css_WEB

我想创建一个div盒子,背景为一个图片,可是显示只有空边框,怎么没有图片 ??




我的动画



div=document.createElement("div");
div.setAttribute("style","width:100px; height:100px; background-image:url(幻片灯.gif); border:red 1px groove; ");
document.body.appendChild(div);





回复讨论(解决方案)

你的图片路径有问题吧?下面的例子是可以的,考虑浏览器兼容性,还是规范写比较好

	div=document.createElement("div");	div.style.width="100px";	div.style.height="100px";	div.style.backgroundImage="url('http://avatar.csdn.net/D/B/7/1_csdn1843321653.jpg')";	div.style.border="red 1px groove";	document.body.appendChild(div); 

查看更多关于求大神赐教,为什么我的图片背景background-image设置没有效果_html/css_WEB的详细内容...

  阅读:37次