如何在网页中制作全屏幕背景

Adh*_*ham 11 html css web

如何将图像作为网页的背景,无论显示此网页的屏幕大小如何?我想正确显示它.怎么样?

小智 25

它非常简单地使用这个css(用你的背景图片替换image.jpg)

body{height:100%;
   width:100%;
   background-image:url(image.jpg);/*your background image*/  
   background-repeat:no-repeat;/*we want to have one single image not a repeated one*/  
   background-size:cover;/*this sets the image to fullscreen covering the whole screen*/  
   /*css hack for ie*/     
   filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='.image.jpg',sizingMethod='scale');
   -ms-filter:"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='image.jpg',sizingMethod='scale')";
}
Run Code Online (Sandbox Code Playgroud)


小智 19

嗯,为什么不把图像设置到底层并放弃所有的烦恼

<img src='yourmom.png' style='position:fixed;top:0px;left:0px;width:100%;height:100%;z-index:-1;'>
Run Code Online (Sandbox Code Playgroud)

  • yourmom.png :). (3认同)
  • @ str8:因为拉伸?只是说. (3认同)