WebKit Inside: px 与 pt

前端CSS中的px是物理像素,还是逻辑像素?

它和iOS中的pt是怎样的关系?

下面我们就来看下CSS中的px实现。

假设有如下CSS字号设置:


   
div {
font-size: 100px;
}

最终处理px的调用栈如下图所示:

image

从左边调用栈可知,这个过程发生在CSS的匹配。

详情可以参看《WebKit Inside: CSS 的匹配》

从右下角红框输出可知,当前正在处理CSSfont-size属性值:100px

从代码可以看到,如果是px,直接从switch-case语句中跳出,不做任何换算处理,属性值100被直接存储下来使用。

那么就可以得出结论,CSS 中的 px 是逻辑像素,等价于 iOS 中的 pt

image

CSS中,也有一个pt,那么它和iOS中的pt是什么关系呢?

还是上面的CSS字号设置,不同的是,将字号单位从px修改为pt:


   
div {
font-size: 100pt;
}

最终处理pt的调用栈如下:

image

整个处理过程和px类似。

不同的地方在于,最终的值不是支持存储100,而是经过了转换。

转换的关键就是CSS::pixelsPerPt,从控制台的输出可以看到,这个值为1.3333

通过在代码中搜索,CSS::pixelsPerPt定义在CSSUnits.h文件中:

image

从定义中看,CSS::pixelsPerPt由另外两个变量计算而来:

CSS::pixelsPerInch = 96

CSS::pointsPerInch = 72

CSS::pixelsPerInch表示一英寸有多少像素,这里的像素是物理像素。

CSS::pointsPerInch表示一英寸有多少点,这里的点是在打印时使用的单位。

CSS::pixelsPerPt就等于CSS::pixelsPerInch除以CSS::pointsPerInch

那么可以得出结论,CSS 中的 pt 是打印时使用的单位,和 iOS 中的 pt 不是一回事

image

原创作者: chaoguo1234 转载于: https://www.cnblogs.com/chaoguo1234/p/18788098
<table class="w-full border-collapse"> <!-- 表头 --> <thead> <tr class="bg-gray-100"> <th colspan="6" class="py-3 px-4 border border-gray-300 font-bold text-gray-800 text-center whitespace-nowrap" > 肉类 </th> <th colspan="6" class="py-3 px-4 border border-gray-300 font-bold text-gray-800 text-center whitespace-nowrap" > 海鲜类 </th> <th colspan="6" class="py-3 px-4 border border-gray-300 font-bold text-gray-800 text-center whitespace-nowrap" > 蔬菜类 </th> <th colspan="6" class="py-3 px-4 border border-gray-300 font-bold text-gray-800 text-center whitespace-nowrap" > 干货类 </th> </tr> <tr class="bg-gray-50 whitespace-nowrap"> <!-- 肉类子表头 --> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 编号 </th> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 物品名 </th> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 数量 </th> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 编号 </th> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 物品名 </th> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 数量 </th> <!-- 海鲜类子表头 --> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 编号 </th> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 物品名 </th> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 数量 </th> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 编号 </th> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 物品名 </th> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 数量 </th> <!-- 蔬菜类子表头 --> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 编号 </th> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 物品名 </th> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 数量 </th> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 编号 </th> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 物品名 </th> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 数量 </th> <!-- 干货类子表头 --> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 编号 </th> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 物品名 </th> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 数量 </th> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 编号 </th> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 物品名 </th> <th class="py-2 px-3 border border-gray-300 text-center text-sm font-semibold text-gray-700" > 数量 </th> </tr> </thead> <!-- 表格内容 --> <tbody> <tr v-for="(row, rowIndex) in displayedItems" :key="rowIndex" class="hover:bg-gray-50 transition-colors duration-150 whitespace-nowrap" > <!-- 肉类数据 --> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800 text-center" > {{ row.meat1?.code || "" }} </td> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800" :style=" row.meat1 ? getSupplierColorStyle(row.meat1.supplierId) : {} " > {{ row.meat1?.name || "" }} </td> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800 text-center" > {{ row.meat1?.quantity || "" }} </td> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800 text-center" > {{ row.meat2?.code || "" }} </td> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800" :style=" row.meat2 ? getSupplierColorStyle(row.meat2.supplierId) : {} " > {{ row.meat2?.name || "" }} </td> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800 text-center" > {{ row.meat2?.quantity || "" }} </td> <!-- 海鲜类数据 --> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800 text-center" > {{ row.seafood1?.code || "" }} </td> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800" :style=" row.seafood1 ? getSupplierColorStyle(row.seafood1.supplierId) : {} " > {{ row.seafood1?.name || "" }} </td> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800 text-center" > {{ row.seafood1?.quantity || "" }} </td> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800 text-center" > {{ row.seafood2?.code || "" }} </td> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800" :style=" row.seafood2 ? getSupplierColorStyle(row.seafood2.supplierId) : {} " > {{ row.seafood2?.name || "" }} </td> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800 text-center" > {{ row.seafood2?.quantity || "" }} </td> <!-- 蔬菜类数据 --> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800 text-center" > {{ row.vegetable1?.code || "" }} </td> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800" :style=" row.vegetable1 ? getSupplierColorStyle(row.vegetable1.supplierId) : {} " > {{ row.vegetable1?.name || "" }} </td> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800 text-center" > {{ row.vegetable1?.quantity || "" }} </td> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800 text-center" > {{ row.vegetable2?.code || "" }} </td> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800" :style=" row.vegetable2 ? getSupplierColorStyle(row.vegetable2.supplierId) : {} " > {{ row.vegetable2?.name || "" }} </td> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800 text-center" > {{ row.vegetable2?.quantity || "" }} </td> <!-- 干货类数据 --> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800 text-center" > {{ row.dry1?.code || "" }} </td> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800" :style="row.dry1 ? getSupplierColorStyle(row.dry1.supplierId) : {}" > {{ row.dry1?.name || "" }} </td> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800 text-center" > {{ row.dry1?.quantity || "" }} </td> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800 text-center" > {{ row.dry2?.code || "" }} </td> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800" :style="row.dry2 ? getSupplierColorStyle(row.dry2.supplierId) : {}" > {{ row.dry2?.name || "" }} </td> <td class="py-2 px-3 border border-gray-300 text-sm text-gray-800 text-center" > {{ row.dry2?.quantity || "" }} </td> </tr> <!-- 空状态 --> <tr v-if="displayedItems.length === 0"> <td colspan="24" class="py-8 text-center text-gray-500 border border-gray-300" > 暂无数据 </td> </tr> </tbody> </table>大小自适应
最新发布
10-23
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值