My requirements are:
- From 1280 to 1920, font size should be fluid 14px to 22px
- Users should be able to zoom as normal
I haven't found a solution that actually does both. Yes I've seen CSS Tricks simplified fluid, using vw of any kind renders zoom ineffective.
clamp(0.875em, 1.146vw, 1.375em)- doesn't scale a the same rate as regular zoom, it's like 5% instead of 50%.clamp(0.875em, 1.4vw - 0.3em, 1.375em)- runs into theminandmaxbut shrinks on zoom.calc(0.875em + 8 * (100vw - 1280) / 640)- doesn't zoom.
In CSS calculations have limitations e.g. multiplication require one of the numbers to be unitless ref. So the formula which we were targeting can't be achieved in CSS:
To cover all requirements we need handle this using JavaScript:
Because StackOverflow puts output in iframe you won't see actual result running the snippet here. Switch to
Full Pageor run the code in separate local HTML file.The way I found zoom level in above code requires code not placed in iframe. Finding zoom level of browser is not an easy task. See the thread for more info.
I didn't get the perceived vs required font size at 150% zoom. Also, let us know what should happen if user zooms out to 50%.