响应式预览与尺寸
按 mobile / tablet / desktop 三档视口算出 iframe 尺寸、缩放比与是否出现横向滚动,输出一份带 media query 的预览文档,并把它放进空 sandbox 的 iframe 里直接渲染出来(文档里的脚本不会执行),这份 HTML 也能下载。
浏览器本地运行所有计算都在你的浏览器里完成,数据不会离开本机。
HTML 源码
结果
处理结果可直接复制。
粘贴 HTML 后即可看到三档视口尺寸
字符数: 0 · 行数: 0 · 视口数: 0 · 删除属性: 0
这个工具能做什么
- 在改样式前先确认三档视口会不会出现横向滚动。
- 拿到各视口的建议尺寸,喂给截图脚本或设计稿。
- 生成一份可下载的预览文档,脱离工具页面也能看。
- 页面上直接看到三档视口的渲染结果,并可下载这份 HTML。
示例
输入
<div width="800">content</div>
输出
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Responsive preview</title>
<style>body{margin:0;background:#f5f6f8;font:13px/1.6 system-ui,sans-serif}.frames{display:flex;flex-wrap:wrap;gap:16px;padding:16px}.frame{background:#fff;border:1px solid #e4e6eb;border-radius:8px;overflow:hidden}.frame figcaption{padding:6px 10px;color:#5b6270}@media (max-width:900px){.frames{flex-direction:column}}</style>
</head>
<body>
<div class="frames">
<figure class="frame"><figcaption>mobile 375×667</figcaption><iframe title="mobile" width="375" height="667"></iframe></figure>
<figure class="frame"><figcaption>tablet 768×1024</figcaption><iframe title="tablet" width="768" height="1024"></iframe></figure>
<figure class="frame"><figcaption>desktop 1440×900</figcaption><iframe title="desktop" width="1440" height="900"></iframe></figure>
<iframe title="mobile" width="375" height="667" src="about:blank" data-viewport="mobile"></iframe>
<iframe title="tablet" width="768" height="1024" src="about:blank" data-viewport="tablet"></iframe>
<iframe title="desktop" width="1440" height="900" src="about:blank" data-viewport="desktop"></iframe>
</div>
</body>
</html>
尺寸是计算结果,渲染靠页面;`<div width="800">` 在 375px 视口下会被标记 `scrollX: true`。
常见问题
它会真的渲染三个 iframe 吗?
会。逻辑侧只负责算尺寸并输出文档,页面把这份文档放进空 sandbox 的 iframe 里渲染,所以 mobile / tablet / desktop 三档是真实画出来的;sandbox 没有开 allow-scripts,文档里的脚本不会执行。
scrollX 是怎么判断的?
取 HTML 里第一个带 `width` 属性的元素值,与该视口宽度比较,超出即为 true;这只是提示,不是布局引擎。
retina 影响什么?
只影响输出里的 scale(mobile/tablet 为 2,desktop 为 1),不改变 CSS 像素尺寸。
gap 有什么限制?
必须是不小于 0 的有限数字,否则抛 `invalid-gap`。
关键词:响应式预览视口尺寸html-responsive-previewviewportiframedeveloper