“GetComputedstyle” Code-Antworten

JS berechnete Stil

// window.getComputedStyle(<element>).<css-attribute>
// example :
window.getComputedStyle(document.getElementById("11")).width
Condemned Crab

GetComputedstyle

let box = document.querySelector('.box');
let style = getComputedStyle(box);

let borderTopWidth = parseInt(style.borderTopWidth) || 0;
let borderLeftWidth = parseInt(style.borderLeftWidth) || 0;
let borderBottomWidth = parseInt(style.borderBottomWidth) || 0;
let borderRightWidth = parseInt(style.borderRightWidth) || 0;
Code language: JavaScript (javascript)
Comfortable Cobra

GetComputedstyle

const htmlBody = document.getElementByTagName("body")[0];
const htmlStyles = window.getComputedStyle(htmlBody);

console.log(htmlStyles["background-color"]); // rgb(243, 242, 239)
console.log(htmlStyles["font-size"]); // 16px
Wissam

Ähnliche Antworten wie “GetComputedstyle”

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen