官术网_书友最值得收藏!

From pixel to root em

Unlike its predecessor, Bootstrap 4 no longer uses pixel (px) as its unit of typographic measurement. Instead, it primarily uses root em (rem). The reasoning behind choosing rem is based on a well-known problem with px; websites using px may render incorrectly, or not as originally intended, as users change the size of the browser's base font. Using a unit of measurement that is relative to the page's root element helps address this problem, as the root element will be scaled relative to the browser's base font. In turn, a page will be scaled relative to this root element.

Typographic units of measurement

Simply put, typographic units of measurement determine the size of your font and elements. The most commonly used units of measurement are px and em. The former is an abbreviation for pixel and uses a reference pixel to determine a font's exact size. This means that for displays of 96 dots per inch ( dpi), 1 px will equal an actual pixel on the screen. For higher resolution displays, the reference pixel will result in the px being scaled to match the display's resolution. For example, specifying a font size of 100 px will mean that the font is exactly 100 pixels in size (on a display with 96 dpi), irrespective of any other element on the page.

EM is a unit of measurement that is relative to the parent of the element to which it is applied. So, for example, if we were to have two nested div elements, the outer element with a font size of 100 px and the inner element with a font size of 2 em, then the inner element's font size would translate to 200 px (as in this case 1 em = 100 px). The problem with using a unit of measurement that is relative to parent elements is that it increases your code's complexity, as the nesting of elements makes size calculations more difficult.

The recently introduced rem measurement aims to address both em's and px's shortcomings by combining their two strengths; instead of being relative to a parent element, rem is relative to the page's root element.
主站蜘蛛池模板: 尚义县| 清镇市| 天峨县| 庄浪县| 滦平县| 平谷区| 侯马市| 明星| 陆河县| 溆浦县| 绥芬河市| 喀什市| 珲春市| 德惠市| 晋城| 长乐市| 福海县| 饶平县| 农安县| 武陟县| 台北市| 都昌县| 武功县| 岳西县| 丰顺县| 东乡族自治县| 洛扎县| 西峡县| 嘉义县| 邵武市| 清原| 肥西县| 南漳县| 延川县| 长治县| 财经| 溧水县| 海伦市| 文成县| 积石山| 高雄市|