Для того, щоб визначити співвідношення сторін , вам потрібно мати співвідношення, на яке слід прагнути.

function getHeight(length, ratio) {
var height = ((length)/(Math.sqrt((Math.pow(ratio, 2)+1))));
return Math.round(height);
}

function getWidth(length, ratio) {
var width = ((length)/(Math.sqrt((1)/(Math.pow(ratio, 2)+1))));
return Math.round(width);
}
У цьому прикладі я використовую, 16:10
оскільки це типове співвідношення сторін монітора.
var ratio = (16/10);
var height = getHeight(300,ratio);
var width = getWidth(height,ratio);
console.log(height);
console.log(width);
Результати зверху були б 147
і300
max-width
іmax-height
на100%
.