Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/433.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 你能帮我最大化我的图像背景吗?_Javascript_Css - Fatal编程技术网

Javascript 你能帮我最大化我的图像背景吗?

Javascript 你能帮我最大化我的图像背景吗?,javascript,css,Javascript,Css,我正在使用这个document.style document.body.style.backgroundImage = "url('okeball-HD.png')"; document.body.style.backgroundPosition = '100% 100%'; document.body.style.backgroundRepeat = 'no-repeat'; document.body.style.backgroundSize = 'cover'; CSS技

我正在使用这个document.style

  document.body.style.backgroundImage = "url('okeball-HD.png')";
  document.body.style.backgroundPosition = '100% 100%';
  document.body.style.backgroundRepeat = 'no-repeat';
  document.body.style.backgroundSize = 'cover';

CSS技巧向您展示了如何做到这一点:

有几种不同的方法可以做到这一点

为图像设置一个div:

<div id="bg">
  <img src="okeball-HD.png" alt="">
</div>

寻求代码帮助的问题必须包含在问题本身中重现代码所需的最短代码。见@Carlo:如果你有解决方案,你应该接受帮助你的答案。
#bg {
  position: fixed; 
  top: -50%; 
  left: -50%; 
  width: 200%; 
  height: 200%;
}
#bg img {
  position: absolute; 
  top: 0; 
  left: 0; 
  right: 0; 
  bottom: 0; 
  margin: auto; 
  min-width: 50%;
  min-height: 50%;
}