steva
asked on
Setting html font-size in WordPress proportional to the viewport width
I've created a template in WordPress and I want the page it generates to scale as the viewport size changes. I've done this outside of WordPress by first expressing all my units in rems and then setting the html font-size proportional to the viewport size by placing the code below in the DOM Ready section:
Actually this starts the scaling when the viewport is < 1400px and In this example, if the viewport were 1200px font_pc would e 53.6% and that would become the html element font-size, reducing everything expressed in rems.
My question is, how can I pull this off for a WordPress template php file?
Thanks
var viewport_width = $( window ).width(); // Returns width of the current browser viewport
if (viewport_width < 1400) {
font_pc = (viewport_width / 1400) * .625 * 100);
$(html).css("font-size", font_pc + '%');
}
Actually this starts the scaling when the viewport is < 1400px and In this example, if the viewport were 1200px font_pc would e 53.6% and that would become the html element font-size, reducing everything expressed in rems.
My question is, how can I pull this off for a WordPress template php file?
Thanks
ASKER
Thank you!
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
(sourced from below link)
When using these units, there are some problems with browser scrollbars, but they can be overcome. Details in this article:
https://web-design-weekly.com/2014/11/18/viewport-units-vw-vh-vmin-vmax/