Skip to content

[html] 第410天 网页打印与标准纸张换算时,cm和px是如何换算的? #2444

Open
@haizhilin2013

Description

@haizhilin2013
Collaborator

第410天 网页打印与标准纸张换算时,cm和px是如何换算的?

3+1官网

我也要出题

Activity

zhaofeipeter

zhaofeipeter commented on Jul 24, 2020

@zhaofeipeter
(function(){
	// 创建一个1cm宽的元素插入到页面,然后坐等出结果
	let div = document.createElement("div");
	div.id = "cm";
	div.style.width = "1cm";
	document.querySelector("body").appendChild(div);
	// 原生方法获取浏览器对元素的计算值
	let cm1 = document.getElementById("cm").getBoundingClientRect();
	console.log(cm1);
	return cm1.width;
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @haizhilin2013@zhaofeipeter

        Issue actions

          [html] 第410天 网页打印与标准纸张换算时,cm和px是如何换算的? · Issue #2444 · haizlin/fe-interview