I have a div (#container) that contains another div (#main) that has a fixed width of 400px and height of 450px.
#main contains two grids: a 6x1 grid and a 7x6 grid.
My goal is to have #main proportionally scale in size, should #container be less than 450px in height, so that the grids within #main remain proportionally exact.
I have used jquery to scale #main on document ready and window resize. This works perfectly when using desktop and scaling the screen.
However, when I test on different devices on Chrome Inspector, #main appears fixed at 400w + 450h. The console logs width & height as less than this. I can’t figure out what the fix is.
function scaleMain() {
let containerHeight = $('#container').height();
let containerWidth = $('#container').width();
if (containerHeight < 450) {
let scaleValue = (containerHeight / 450. * 100)
$('#main').css("transform", "scale(0." + scaleValue + ")");
} else if (containerHeight < 400) {
let scaleValue = (containerHeight / 400. * 100)
$('#main').css("transform", "scale(0." + scaleValue + ")");
} else {
$('#main').css("transform", "none");
}
console.log('Container Height: ' + containerHeight + 'px')
console.log('Container Width: ' + containerWidth + 'px')
}
$(document).ready(function() {
scaleMain();
});
$(window).resize(function() {
scaleMain();
});
Many thanks