“GetCompuledstyle” Réponses codées

style calculé js

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

GetCompuledstyle

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

GetCompuledstyle

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

Réponses similaires à “GetCompuledstyle”

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code