Regarding the viewport meta tag, I want to establish different viewports at different screen sizes.
The reason for this is that I want to set a non-fluid layout for tablets that scales when you flip them vertically, but I want a different set of layouts for mobile devices.
How can this be done?
Using the link that cjspurg posted above as a starting point, I eventually came up with a method to reliably detect the screen width (in CSS pixels) and set the viewport accordingly:
<meta id="testViewport" name="viewport" content="width=1024">
<script>
var sw = screen.width;
var sh = screen.height;
if ( window.matchMedia("(orientation: landscape)").matches ) {
var fw = sh;
} else {
var fw = sw;
}
if (fw < 768) {
var mvp = document.getElementById("testViewport");
mvp.setAttribute("content","width=device-width,initial-scale=1");
}
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With