加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

html – 即使我在Chrome调试工具中更改视口,为什么网站的宽度也

发布时间:2020-12-14 18:37:08 所属栏目:资源 来源:网络整理
导读:我正在使用Chrome调试工具的Viewport模拟器.我发现奇怪的是,无论视口宽度如何,Chrome总是以像素为单位报告相同的宽度,并且缩放和DeviceToPixelRation(DPR)都不会更改. h1的样式设置宽度为100%,没有其他代码.我希望在视口宽度改变时宽度或DPR会改变.为什么不
我正在使用Chrome调试工具的Viewport模拟器.我发现奇怪的是,无论视口宽度如何,Chrome总是以像素为单位报告相同的宽度,并且缩放和DeviceToPixelRation(DPR)都不会更改. h1的样式设置宽度为100%,没有其他代码.我希望在视口宽度改变时宽度或DPR会改变.为什么不发生?

这是代码:

<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        h1 {
            width: 100%;
            background: blue
        }
    </style>
</head>
<body>
<h1>
    Some header text here
</h1>

解决方法

以下是 here的引用:

To attempt to provide the best experience,mobile browsers render the
page at a desktop screen width
(usually about 980px,though this
varies across devices),and then try to make the content look better
by increasing font sizes and scaling the content to fit the screen.
This means that font sizes may appear inconsistent to users,who may
have to double-tap or pinch-to-zoom in order to see and interact with
the content.

这就是宽度不变的原因.浏览器只需缩小整个网页以适应屏幕.

Using the meta viewport value width=device-width instructs the page to
match the screen’s width in device-independent pixels.

这就是为什么它使用name =“viewport”标签调整宽度.

这似乎有效:

<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">

有关更多信息,请阅读文档on viewport meta tag at MDN.:

The viewport meta tag tells the browser that the width of the screen should be considered the “Full Width” of the page. Meaning no matter the width of the device you are on,whether on desktop or mobile. The website will follow the width of the device the user is on.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读