如何更改 html 的背景屬性?我能夠更改 body 元素的背景,但我想操作 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.html.style = 'background: red';
document.style = 'background: red';
我想改變這部分
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%);
}
uj5u.com熱心網友回復:
您需要使用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>
uj5u.com熱心網友回復:
通過 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%)";
uj5u.com熱心網友回復:
只需在 DOM 中放置一個 background-div 并對其進行操作。eG 位置:絕對/z-index:-1
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/364988.html
標籤:javascript html css 背景
