I use this code in JS:
bigPhoto.setAttribute("width", "200rem");
The result is in pixel in html source,
But:
When I change it to 20rem the photo become really small.
I couldn't solve the problem which is mentioned in the photos.
I use this code in JS:
bigPhoto.setAttribute("width", "200rem");
The result is in pixel in html source,
But:
When I change it to 20rem the photo become really small.
I couldn't solve the problem which is mentioned in the photos.
Share Improve this question edited Sep 9, 2018 at 20:28 t3ol5 947 bronze badges asked Apr 10, 2016 at 16:22 Malus JanMalus Jan 2,1082 gold badges25 silver badges27 bronze badges 3 |2 Answers
Reset to default 276Another method would be to convert rem into pixels:
function convertRemToPixels(rem) {
return rem * parseFloat(getComputedStyle(document.documentElement).fontSize);
}
This can be useful when you must perform some arithmetic in js (such as using the position of the mouse to display a tooltip...)
The HTML width attribute only takes an integer number of pixels or a percentage (followed by a % sign).
If you wish to use CSS length units you have to use CSS (and set bigPhoto.style.width = "200rem"
.
rem
orem
? – user2705585 Commented Apr 10, 2016 at 16:25rem
. Apparently, your base font size is10px
so that20rem = 200px
– Adam Jenkins Commented Apr 10, 2016 at 16:28