分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 前端开发

CSS中的单位

发布时间:2023-09-06 02:20责任编辑:熊小新关键词:CSS

absolute units

  • in 英寸
  • cm 厘米
  • mm 毫米  
  • pt 磅 (1 pt 等于 1/72 英寸)
  • pc  12点活字 (1 pc 等于 12 点)

The relation between the absolute units is as follows: 1in = 2.54cm = 25.4mm = 72pt = 6pc

绝对单位之间的关系如下:1in = 2.54cm = 25.4mm = 72pt = 6pc

relative units

  • em

  1em 等于当前的字体尺寸。

  2em 等于当前字体尺寸的两倍。

  例如,如果某元素以 12pt 显示,那么 2em 是24pt。

  在 CSS 中,em 是非常有用的单位,因为它可以自动适应用户所使用的字体。

  The em and ex units depend on the font and may be different for each element in the document. The em is simply the font size. In an element with a 2in font, 1em thus means 2in. Expressing sizes, such as margins and paddings, in em means they are related to the font size, and if the user has a big font (e.g., on a big screen) or a small font (e.g., on a handheld device), the sizes will be in proportion. 

  em和ex单位取决于字体,对于文档中的每个元素可能不同。 em只是字体大小。 在具有2英寸字体的元素中,1em因此意味着2英寸。 在em中表示大小(例如边距和填充)意味着它们与字体大小相关,并且如果用户具有大字体(例如,在大屏幕上)或小字体(例如,在手持设备上),则尺寸会保持比例。

  • ex

  一个 ex 是一个字体的 x-height。 (x-height 通常是字体尺寸的一半。)

  The ex unit is rarely used. Its purpose is to express sizes that must be related to the x-height of a font. The x-height is, roughly, the height of lowercase letters such as a, c, m, or o. Fonts that have the same size (and thus the same em) may vary wildly in the size of their lowercase letters, and when it is important that some image, e.g., matches the x-height, the ex unit is available.

  ex单位很少使用。 其目的是表示必须与字体的x-height相关的大小。 x高度大致是小写字母的高度,例如a,c,m或o。 具有相同大小(并因此相同的em)的字体可能在其小写字母的大小上变化很大,并且当一些图像(例如,匹配x-height)很重要时,ex单元是可用的。

  • px 像素  计算机屏幕上的一个点

    px不被定义为恒定长度,而是取决于设备的类型及其典型用途。

CSS中的单位

原文地址:https://www.cnblogs.com/HL345/p/9892544.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved