HTML5技术

你可能不知道的7个CSS单位 - jerrylsxu(2)

字号+ 作者:H5之家 来源:博客园 2016-05-27 12:04 我要评论( )

div class="box"style=" margin: 0px !important; padding: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; bo

<div class="box" style=" margin: 0px !important; padding: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; min-height: inherit !important; background: none !important;">>

    fdasjfdlas

</div>

五、ex 和 ch

ex、ch单位与em、rem相似之处在于都依赖于font-size,但是ex、ch还依赖于font-family,基于font-specific来计算。 引用w3C规范:

ex unit Equal to the used x-height of the .  The x-height is so called because it is often equal to the height of the lowercase "x". However, an ‘’ is defined even for fonts that do not contain an "x". The x-height of a font can be found in different ways. Some fonts contain reliable metrics for the x-height. If reliable font metrics are not available, UAs may determine the x-height from the height of a lowercase glyph. One possible heuristic is to look at how far the glyph for the lowercase "o" extends below the baseline, and subtract that value from the top of its bounding box. In the cases where it is impossible or impractical to determine the x-height, a value of 0.5em must be assumed. ch unit Equal to the used advance measure of the "0" (ZERO, U+0030) glyph found in the font used to render it.  

用一副图来解释这两种单位的含义:

css-units

这两种单位,有许多用途,大部分是用于印刷时的微调整。例如,sup、sub元素分别显示上标和下标,但是我们可以使用position和bottom模拟:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

<style type="text/css">

body {

    margin: 0;

    padding:0;

}

 

.sup {

    position: relative;

    bottom: 1ex;

}

.sub {

    position: relative;

    bottom: -1ex;

}

</style>

<div>

    AaB<span class="sup">b</span>CcXxD<span class="sub">d</span>EeFf

</div>

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • 这个发现是否会是RSA算法的BUG、或者可能存在的破解方式? - Bro__超

    这个发现是否会是RSA算法的BUG、或者可能存在的破解方式? - Bro__超

    2017-01-21 14:01

  • css-单位%号-background-size-background-position-遁地龙卷风 - 遁地龙卷风

    css-单位%号-background-size-background-position-遁地龙卷风 - 遁

    2016-10-15 18:00

  • NanUI for Winform发布,让Winform界面设计拥有无限可能 - 林选臣

    NanUI for Winform发布,让Winform界面设计拥有无限可能 - 林选臣

    2016-05-19 18:01

  • 移动开发之设计稿转换页面单位尺寸 - 海角在眼前

    移动开发之设计稿转换页面单位尺寸 - 海角在眼前

    2016-05-01 14:00

网友点评
8