Use rem to set the text size

Source: Internet
Author: User

Setting the text size with px is not normal, for example

{:;}

It can be seen everywhere that px is used to set width and height, which is also a careful and secure setting method. The disadvantage of this method is that adjusting the browser's text size does not affect the text in pixels, this causes inconvenience to some users.

This problem is corrected by setting the text size with em, which is a relative unit. When the text size is expressed in em, it can be increased (smaller) with the browser font size (for example, "set-> advanced settings-> font size" in chrome ), the format is basically the same as that of px, for example

{:;}

The above p element is used as an example. The em calculation method is as follows:

Using em has a headache:

Assume that the document structure is as follows: html> p> span. The style is as follows:

{
:; Token}
{

Now I want to set the text size of span to 12px, and I need to calculate 12/14 = 85.7%

{
:}

If you want to set the text size of the face node in the span, the calculation will become more and more painful...

This is the time for the emergence of rem.

Rem is introduced in CSS3. rem refers to the text size of the root element (html). IE9 + is supported by mainstream versions such as Firefox, Chrome, Safari, and Opera.

After the text size of the root node is set, the text size of all child nodes is calculated relative to that of the root node. For example, if html is 10px, 1.2rem = 12px, 2rem = 20px... and so on.

{:;}{:;:;}{:;:;}

To be compatible with browsers that do not support rem, write the corresponding px value before setting rem to achieve elegant degradation.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.