I want to convert rem to px and I have referred to
https://stackoverflow.com/a/11353068/19743544
Target Size / Base Size = Value
This basically means rem * base size = px, but why the result from the calculation by this formula is different from the one calculated by the browser?
const elm = document.querySelector('#test'),
style = window.getComputedStyle(elm),
paddingLeft = style.getPropertyValue('padding-left');
const bmFontSize = Number(window.getComputedStyle(document.body).getPropertyValue('font-size').match(/\d+/)),
remValue = 9.375,
result = remValue * bmFontSize;
console.log(paddingLeft, result);
body {
font-size: 15px;
}
#test {
padding-left: 9.375rem;
}
<div id="test"></div>