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

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.
主站蜘蛛池模板: 镇原县| 福安市| 绥中县| 绵竹市| 资阳市| 洛南县| 玉树县| 西乡县| 香港 | 法库县| 奉新县| 兖州市| 富源县| 大城县| 义马市| 正蓝旗| 云安县| 徐水县| 湖南省| 辛集市| 合江县| 夏河县| 山丹县| 遂昌县| 江北区| 繁峙县| 晋江市| 罗山县| 肃宁县| 葫芦岛市| 孟津县| 宜良县| 罗平县| 天柱县| 韶关市| 孝感市| 封开县| 斗六市| 昌平区| 静安区| 福清市|