I have created a variant of https://stackoverflow.com/a/312960/
where you can set the minimum and maximum text size in relation to the minimum and maximum size of the field that you want to "check". In addition, you can check the size of the dom element other than the field in which you want to apply the text size.
You change the text size between 19px and 25px on the # size-2 element based on the width of 500px and 960px of the # size-2 element
resizeTextInRange(500,960,19,25,'#size-2');
You change the text size between 13px and 20px on the element # size-1, based on the width of the body of the body 500px and 960px.
resizeTextInRange(500,960,13,20,'#size-1','body');
the full code is https://github.com/kiuz/sandbox-html-js-css/tree/gh-pages/text-resize-in-range-of-text-and-screen/src
function inRange (x,min,max) { return Math.min(Math.max(x, min), max); } function resizeTextInRange(minW,maxW,textMinS,textMaxS, elementApply, elementCheck=0) { if(elementCheck==0){elementCheck=elementApply;} var ww = $(elementCheck).width(); var difW = maxW-minW; var difT = textMaxS- textMinS; var rapW = (ww-minW); var out=(difT/100)*(rapW/(difW/100))+textMinS; var normalizedOut = inRange(out, textMinS, textMaxS); $(elementApply).css('font-size',normalizedOut+'px'); console.log(normalizedOut); } $(function () { resizeTextInRange(500,960,19,25,'#size-2'); resizeTextInRange(500,960,13,20,'#size-1','body'); $(window).resize(function () { resizeTextInRange(500,960,19,25,'#size-2'); resizeTextInRange(500,960,13,20,'#size-1','body'); }); });