“So ändern Sie die CSS -Variable in JavaScript” Code-Antworten

So ändern Sie eine CSS -Variable mit JavaScript

var root = document.querySelector(':root');
root.style.setProperty('--variable', 'lightblue');
/or/
root.style.setProperty('--variable', myColor); 
Spotless Seal

JavaScript erhalten CSS -Variable

let docStyle = getComputedStyle(document.documentElement);

//get variable
let myVarVal docStyle.getPropertyValue('--my-variable-name');

//set variable
docStyle.setProperty('--my-variable-name', '#fff');
garzj

JavaScript erhalten CSS -Variable

getComputedStyle(document.documentElement)
    .getPropertyValue('--my-variable-name'); // #999999
DJ Ultimate Disco Party

So ändern Sie die CSS -Variable in JavaScript

document.documentElement.style.setProperty("--main-background-color", "green");
PYTHON_NOT_SNAKE.py

So ändern Sie die CSS -Variable in JavaScript

document.documentElement.setAttribute("style", "--main-background-color: green");
PYTHON_NOT_SNAKE.py

So ändern Sie die CSS -Variable in JavaScript

document.documentElement.style.cssText = "--main-background-color: red";
PYTHON_NOT_SNAKE.py

Ähnliche Antworten wie “So ändern Sie die CSS -Variable in JavaScript”

Fragen ähnlich wie “So ändern Sie die CSS -Variable in JavaScript”

Weitere verwandte Antworten zu “So ändern Sie die CSS -Variable in JavaScript” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen