Home > Web Front-end > CSS Tutorial > What are the classifications of css units?

What are the classifications of css units?

百草
Release: 2023-10-16 17:37:38
Original
2057 people have browsed it

CSS unit classification includes absolute units and relative units. Detailed introduction: 1. Absolute units are units related to physical dimensions, and their values ​​remain fixed in different devices and environments, including pixels, inches, centimeters, millimeters, and points; 2. Relative units are units relative to other sizes or environments. , its value will change according to the context. Relative units can implement responsive layout and adapt to the needs of different screen sizes, including percentages, window units, font relative units and relative length units. Choosing the right unit allows for precise control and adaptability to different screen sizes.

What are the classifications of css units?

The operating system for this tutorial: Windows 10 system, DELL G3 computer.

Units in CSS can be classified according to their characteristics and uses. According to common classification methods, CSS units can be divided into the following categories:

1. Absolute Units: Absolute units are units related to physical dimensions, and their values ​​are maintained across different devices and environments. fixed. Common absolute units are:

- Pixel (Pixel, px): Pixel is the most commonly used absolute unit and represents a point on the screen. Pixels are fixed and do not change based on screen size. In CSS, pixels are often used to specify attributes such as size, spacing, and borders of elements.

- Inch (Inch, in): Inch is a physical unit, indicating that 1 inch is equal to 2.54 centimeters. In CSS, you can specify the size of an element using inches as the unit of size.

- Centimeter (cm): Centimeter is a physical unit, indicating that 1 centimeter is equal to 0.3937 inches. In CSS, you can specify the size of an element using centimeters as the unit of size.

- Millimeter (mm): Millimeter is a physical unit, indicating that 1 millimeter is equal to 0.03937 inches. In CSS, you can specify the size of an element using millimeters as the unit of size.

- Point (Point, pt): Point is a physical unit, indicating that 1 point is equal to 1/72 inch. In CSS, you can specify the size of an element using points as the unit of size.

2. Relative Units: Relative units are units relative to other dimensions or the environment, and their values ​​will change according to changes in context. Relative units enable responsive layout and adapt to different screen sizes. Common relative units are:

- Percentage (%): Percentage is a unit of measurement relative to the parent element. In CSS, you can use percentages to specify the size, margins, padding, and other properties of elements. For example, width: 50%; means that the width of the element is 50% of the width of the parent element.

- Viewport Units: Viewport units are units of measurement relative to the browser viewport. Viewport units resize elements based on the size of the browser window. Common window units are:

- Viewport Width (vw): The window width unit represents a percentage relative to the width of the browser window. For example, width: 50vw; means that the width of the element is 50% of the width of the browser window.

- Viewport Height (vh): The window height unit represents a percentage relative to the height of the browser window. For example, height: 50vh; means that the height of the element is 50% of the height of the browser window.

- Viewport Minimum Width (vmin): The minimum width unit of the viewport represents the percentage relative to the smaller of the browser window width and height. For example, width: 50vmin; means that the width of the element is 50% of the smaller of the browser window width and height.

- Viewport Maximum Width (vmax): The maximum width unit of the viewport represents a percentage relative to the larger of the browser window width and height. For example, width: 50vmax; means that the width of the element is 50% of the larger of the browser window width and height.

- Font Relative Units: Font relative units are units relative to the font size. Common font relative units are:

- em: The em unit is a multiple of the font size relative to the element. For example, font-size: 1.2em; means that the font size is 1.2 times the font size of the parent element.

- rem: The rem unit is a multiple of the font size relative to the root element (that is, the html element). For example, font-size: 1.5rem; means that the font size is 1.5 times the font size of the root element.

- ch: The ch unit is a multiple of the width of the "0" character. For example, width: 10ch; means that the width of the element is 10 times the width of the "0" character.

- Relative Length Units: Relative length units are units relative to a certain attribute value of the element itself. Common relative length units are:

- rem: The rem unit is a multiple of the font size relative to the root element (that is, the html element). In CSS, you can use rem units to specify the size, spacing, borders and other attributes of elements. The rem unit is often used to implement relative dimensions of the entire page.

- em: The em unit is a multiple of the font size relative to the element. In CSS, you can use em units to specify the size, spacing, borders and other attributes of elements. The em unit can adjust the size of an element based on its own font size.

The selection of these units depends on specific needs and design requirements. Absolute units are suitable for situations where precise control of size is required, while relative units are suitable for situations where responsive layout and adaptability to different screen sizes are required. When choosing units, you need to take into account the differences between different devices and screens to ensure that the page is consistent and adaptable on different devices.

To summarize, CSS units can be classified according to their characteristics and uses, including absolute units (pixels, inches, centimeters, millimeters, points) and relative units (percentage, window units, font relative units). Relative units can also be subdivided into relative length units. Choosing the right unit allows for precise control and adaptability to different screen sizes.

The above is the detailed content of What are the classifications of css units?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template