Returns the value of a CSS rule for the specified element.

Use Window.getComputedStyle() to get the value of the CSS rule for the specified element.

代码片段

const getStyle = (el, ruleName) => getComputedStyle(el)[ruleName];

使用样例

getStyle(document.querySelector('p'), 'font-size'); // '16px'