What is em? em refers to the font height, and the default font height of any browser is 16px. So all unadjusted browsers will conform to: 1em=16px. Then 12px=0.75em, 10px=0.625em. To simplify font-size conversion, you need to declare Font-size=62.5% in the body selector in CSS. This will change the em value to 16px*62.5%=10px, so 12px=1.2em, 10px=1em. In other words, you only need to divide your original px value by 10 and then use em as the unit. em has the following characteristics: 1. The value of em is not fixed; 2. em will inherit the font size of the parent element. Rewrite steps: 1. Declare Font-size=62.5% in the body selector; 2. Divide your original px value by 10, and then use em as the unit; It’s simple, right? If the problem can be solved with just the above two steps, no one would use px. After the above two steps, you will find that the fonts on your website are larger than you imagined. Because the value of em is not fixed and will inherit the size of the parent element, you may set the font size in the content div to 1.2em, which is 12px. Then you set the font size of the selector p to 1.2em, but if p is a child of content, the font size of p is not 12px, but 1.2em = 1.2 * 12px = 14.4px. This is because the font size of content is set to 1.2em. This em value inherits the size of its parent element body, which is 16px * 62.5% * 1.2=12px. As p is its child, em inherits the font height of content, which is 12px. So 1.2em of p is no longer 12px, but 14.4px. 3. Recalculate the em values of the fonts that are enlarged. Avoid repeated declarations of font sizes, that is, avoid the phenomenon of 1.2 * 1.2 = 1.44 mentioned above. For example, if you declare the font size in #content as 1.2em, then when declaring the font size of p, it can only be 1em, not 1.2em, because this em is not that em. It inherits the font height of #content and becomes 1em=12px. |
<<: Creating private members in JavaScript
This article shares the specific code of JavaScri...
Use HTML CSS and JavaScript to implement a simple...
The purpose of using HTML to mark up content is t...
The installation tutorial of MySQL 5.7.27 is reco...
Table of contents Written in front Two-way encryp...
SQLyog connects to mysql error number 1129: mysql...
Preface I recently used a virtual machine to inst...
After reading the following article, you can depl...
Linux and Unix are multi-user operating systems, ...
1. Document flow and floating 1. What is document...
Use JS to zoom in and out when the mouse is on th...
The fd command provides a simple and straightforw...
The installation tutorial of mysql 8.0.11 winx64 ...
Table of contents The origin of JSBridge The bidi...
Table of contents 1. Install Node Exporter 2. Ins...