如何设置初始比例元标记以适合 body 宽度?

How to set the initial scale meta tag to fit body width?

我有一个页面在 500 像素宽度以下看起来很糟糕。在宽度小于 500px 的移动设备中,有什么方法可以自动设置初始比例元标记以适应宽度为 body 的视口宽度?

我已经尝试将 body 的 min-width 设置为 500px,但显然,必须手动缩小才能在宽度小于 500px 的屏幕上看到完整页面。

您可以使用 JavaScript。你尝试过这样的事情吗?

<meta id="viewport" name="viewport" content="width=device-width, initial-scale=1">
<script>
    window.onload = function() {
        if (screen.width < 500) {
            var metaViewport = document.getElementById('viewport');
            metaViewport.setAttribute('content', 'user-scalable=no,width=500');
        }
    }
</script>