“Ustaw CSS var z JavaScript” Kod odpowiedzi

Jak zmienić zmienną CSS z JavaScript

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

Jak zmienić zmienną CSS w JavaScript

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

Ustaw CSS var z JavaScript

// this is for site-navigation with more sub ul-blocks.
// in css root{--ul-hover-height:100px} //fallbackvalue 
// in css: nav ul ul:hover{height:--ul-hover-height;}

// to make it dynamic using JS: 
// set variable ul ul height depending on nr. of li's:
function setUlHeight(elem){        
    parentHeight=window.getComputedStyle(elem.parentNode).height
    parentHeight=parseInt(parentHeight)*1.2 //to cover li padding/margin..
    elemHeight=parentHeight * elem.childElementCount
Zenity Code

Ustaw zmienną CSS z JavaScript

document.documentElement.style.cssText = "--tab-count: 3";
/or/
document.documentElement.style.setProperty("--tab-count", 5);
/or/
document.documentElement.setAttribute("style", "--tab-count: 5");
Vivacious Vendace

Ustaw CSS var z JavaScript

// this is for site-navigation with more sub ul-blocks.
// in css root{--ul-hover-height:100px} //fallbackvalue 
// in css: nav ul ul:hover{height:--ul-hover-height;}

// to make it dynamic using JS: 
// set variable ul ul height depending on nr. of li's:
function setUlHeight(elem){        
    parentHeight=window.getComputedStyle(elem.parentNode).height
    parentHeight=parseInt(parentHeight)*1.2 //to cover li padding/margin..
    elemHeight=parentHeight * elem.childElementCount
  
    let root = document.documentElement;           
    root.style.setProperty('--ul-hover-height', elemHeight); }
Donna Maria

Jak zmienić zmienną CSS w JavaScript

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

Odpowiedzi podobne do “Ustaw CSS var z JavaScript”

Pytania podobne do “Ustaw CSS var z JavaScript”

Więcej pokrewnych odpowiedzi na “Ustaw CSS var z JavaScript” w JavaScript

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu