Skip to content
This repository was archived by the owner on Jan 8, 2025. It is now read-only.

Commit 290edf9

Browse files
committed
Add CSS unit guidelines
1 parent caad284 commit 290edf9

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Diff for: languages/css.md

+12
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,15 @@ If you need to learn CSS from scratch, refer to these resources:
1313
* [`em` and `rem`](https://webdesign.tutsplus.com/tutorials/comprehensive-guide-when-to-use-em-vs-rem--cms-23984)
1414
* [Stacking context](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Positioning/Understanding_z_index/The_stacking_context)
1515
* [Grid](https://gridbyexample.com/)
16+
17+
## CSS length units
18+
19+
CSS provides numerous ways of specifying dimensions. There is no single "right" way - each has its own purpose:
20+
21+
* `px`: small border dimensions (e.g. 1-2px) and image sizes
22+
* `em`: use for specifying font size and padding relative to the element's font size
23+
* Use with caution: setting padding in `em` may initially seem to make sense, but on a page with sections that are aligned, either vertically or horizontally, if they have different font sizes and padding specified in `em` then they will have different padding values, causing a visual mis-alignment of content across sections.
24+
* `rem`: use for specifying font size, margin, and padding relative to the whole page. Margin and padding should usually use `rem` to maintain consistency throughout the page.
25+
* `%`: use for specifying width/height of an element that should adjust relative to its container
26+
* `vh/vw`: use for specifying width/height of an element that should adjust relative to the viewport size
27+
* `pt` (and others not listed): do not use

0 commit comments

Comments
 (0)