Skip to content

Instantly share code, notes, and snippets.

@udovichenko
Last active August 1, 2018 19:35
Show Gist options
  • Save udovichenko/c55185efd4d08f1ad0299c02bd309a69 to your computer and use it in GitHub Desktop.
Save udovichenko/c55185efd4d08f1ad0299c02bd309a69 to your computer and use it in GitHub Desktop.
Calculation of mixed font-size: calc(px + vw) by two breakpoint values
var w1 = 360; // first breakpoint window width
var w2 = 1920; // second breakpoint window width
var fz1 = 20; // first breakpoint required font-size
var fz2 = 55; // second breakpoint required font-size
var px, vw;
vw = (fz1 - fz2) / (w1 - w2);
px = parseInt(fz2 - w2 * vw);
vw *= 100;
vw = vw.toFixed(1);
console.log('calc(' + px + 'px + ' + vw + 'vw)'); // calc(32px + 2.2vw)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment