<meta>标签 name="viewpo

作者: 风之清 | 来源:发表于2018-06-11 08:56 被阅读29次
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

转载于 Lew's Blog

什么是Viewport

手机浏览器是把页面放在一个虚拟的“窗口”(viewport)中,通常这个虚拟的“窗口”(viewport)比屏幕宽,这样就不用把每个网页挤到很小的窗口中(这样会破坏没有针对手机浏览器优化的网页的布局),用户可以通过平移和缩放来看网页的不同部分。移动版的 Safari 浏览器最新引进了 viewport 这个 meta tag,让网页开发者来控制 viewport 的大小和缩放,其他手机浏览器也基本支持。

Viewport 基础

一个常用的针对移动网页优化过的页面的 viewport meta 标签大致如下:
<meta name=”viewport” content=”width=device-width, initial-scale=1, maximum-scale=1″>
width:控制 viewport 的大小,可以指定的一个值,如果 600,或者特殊的值,如 device-width 为设备的宽度(单位为缩放为 100% 时的 CSS 的像素)
height:和 width 相对应,指定高度
initial-scale:初始缩放比例,也即是当页面第一次 load 的时候缩放比例
maximum-scale:允许用户缩放到的最大比例
minimum-scale:允许用户缩放到的最小比例
user-scalable:用户是否可以手动缩放

shrink-to-fit=no

下面的一行代码可以让网页的宽度自动适应手机屏幕的宽度:
<meta name="viewport" content="width=device-width, initial-scale=1">
但在iOS9中要想起作用,得加上"shrink-to-fit=no",原因如下:
Viewport meta tags using "width=device-width" cause the page to scale down to fit content that overflows the viewport bounds. You can override this behavior by adding "shrink-to-fit=no" to your meta tag as shown below. The added value will prevent the page from scaling to fit the viewport.


Reference

  1. HTML meta viewport属性说明
  2. shrink-to-fit和shrink-to-fit=no

相关文章

  • <meta>标签 name="viewpo

    转载于 Lew's Blog 什么是Viewport 手机浏览器是把页面放在一个虚拟的“窗口”(viewport...

  • HTML特效代码大全

    来源于网络,仅供自己记录方便以后查看。 1)贴图:<img src="图片地址">...

  • xml文件中字符需要转义

    < < 小于 > > 大于 & & 且 '' 单引号 " " 双引号

  • python替换转义字符

    python字符串处理有时候会出现< >&" 等转义字符HTML的< >...

  • <meta>标签简介

    元素可提供有关页面的元数据(metadata),比如针对搜索引擎和更新频度的描述和关键词 常用的属性 - char...

  • HTML: <meta>标签

    引子 下面具体介绍一下meta的功能和使用。 前言 meta是html语言head区的一个辅助性标签。也许你认为这...

  • 关于html 的一些问题 2020-04-02

    html 源码中含有" . < . > 等符号 对应的html 源码是: html 源码...

  • <meta>标签的使用

    控制显示区域各种属性: width – viewport的宽度 heig...

  • XML转义

    转义符号解释<<小于号>>大于号&&和''单引号""双引号

  • 利用<meta>标签优化网站信息

    自己辛辛苦苦做出来的心爱网站怎能没有搜索引擎优化(SEO)?对 标签的了解还停留在 ? 对浏览器的支持...

网友评论

    本文标题:<meta>标签 name="viewpo

    本文链接:https://www.haomeiwen.com/subject/qksceftx.html