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

WBOY
Release: 2016-06-21 08:57:28
Original
1678 people have browsed it

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


    
    我的动画
    
  
    <script> <br /> div=document.createElement("div"); <br /> div.setAttribute("style","width:100px; height:100px; background-image:url(幻片灯.gif); border:red 1px groove; "); <br /> document.body.appendChild(div); <br /> </script>
  
    
    


回复讨论(解决方案)

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

	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);
Copy after login

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template