[英]Changing the background property of the html, not the body
How do I change the background property of the html?如何更改 html 的背景属性? I was able to change the background of the body element, but I want to manipulate the html "tag" (?).
我能够更改 body 元素的背景,但我想操纵 html“标签”(?)。
Code to manipulate the body background操纵身体背景的代码
document.body.style = 'background: radial-gradient(circle, rgba(131,170,203,1) 4%, rgba(69,113,148,1) 50%, rgba(39,71,97,1) 100%);';
These attempts didn't work这些尝试没有奏效
document.html.style = 'background: red';
document.style = 'background: red';
I want to change this part我想改变这部分
html {
font-family: Arial, Helvetica, sans-serif;
color: white;
-webkit-user-drag: none;
user-select: none;
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
background: radial-gradient(circle, rgba(131,170,203,1) 4%, rgba(69,113,148,1) 50%, rgba(39,71,97,1) 100%);
}
change background by javascript in html tag try this:通过 html 标签中的 javascript 更改背景试试这个:
document.getElementsByTagName('html')[0].style.background="radial-gradient(circle, rgba(131,170,203,1) 4%, rgba(69,113,148,1) 50%, rgba(39,71,97,1) 100%)";
You need to use document.documentElement.style
to target the html
element.您需要使用
document.documentElement.style
来定位html
元素。
document.body.style = 'background: radial-gradient(circle, rgba(131,170,203,1) 4%, rgba(69,113,148,1) 50%, rgba(39,71,97,1) 100%);'; document.documentElement.style = 'background: red';
<html> <body> <p>test</p> </body> </html>
just put a background-div in the DOM and manipulate it.只需在 DOM 中放置一个 background-div 并对其进行操作。 eG position: absolute / z-index: -1
eG position:绝对/z-index:-1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.