the murmurous sea

CSS. units 본문

#dev/개념정리

CSS. units

lunacer 2020. 4. 13. 13:08

- CSS has several different units for expressing a length.
- A whitespace cannot appear between the number and the unit. However, if the value is 0, the unit can be omitted.

- For some CSS properties, negative lengths are allowed.

 

There are two types of length units: absolute and relative.

1. Absolute Lengths
Absolute length units are not recommended for use on screen, because screen sizes vary so much. However, they can be used if the output medium is known, such as for print layout.

cm  centimeters  
mm  millimeters  
in  inches (1in = 96px = 2.54cm)  
px  pixels (1px = 1/96th of 1in) Pixels (px) are relative to the viewing device. 
For low-dpi devices, 1px is one device pixel (dot) of the display.
For printers and high resolution screens 1px implies multiple device pixels.
pt  points (1pt = 1/72 of 1in)  
pc  picas (1pc = 12 pt)  

 

2. Relative Lengths

Relative length units specify a length relative to another length property. Relative length units scale better between different rendering mediums.
- The em and rem units are practical in creating perfectly scalable layout!
- Viewport = the browser window size. If the viewport is 50cm wide, 1vw = 0.5cm.

em Relative to the font-size of the element font-size
(of parent/root/current/0)
rem Relative to font-size of the root element
ex Relative to the x-height of the current font (rarely used)
ch Relative to width of the "0" (zero)
vw Relative to 1% of the width of the viewport* viewport
vh Relative to 1% of the height of the viewport
vmin Relative to 1% of viewport's* smaller dimension
vmax Relative to 1% of viewport's* larger dimension
% Relative to the parent element parent element

https://www.w3schools.com/cssref/css_units.asp

 

CSS Units

CSS Units CSS Units CSS has several different units for expressing a length. Many CSS properties take "length" values, such as width, margin, padding, font-size, etc. Length is a number followed by a length unit, such as 10px, 2em, etc. A whitespace cannot

www.w3schools.com

https://webclub.tistory.com/356

 

CSS의 7가지 단위 - rem, vh, vw, vmin, vmax, ex, ch

CSS Unit (CSS 7가지 단위) 우리가 잘 알고 있는 CSS기술을 사용하는 것은 쉽고 간단할 수 있지만 새로운 문제에 봉착하게 되면 해결하기 어려울 수 있습니다. 웹은 항상 성장,변화하고 있고 새로운 해결방안 역시..

webclub.tistory.com

 

'#dev > 개념정리' 카테고리의 다른 글

CSS: vertical alignment - centering  (0) 2020.04.15
HTML. semantic / non-semantic elements  (0) 2020.04.13
Poptrox  (0) 2020.04.13
@-ms-viewport {width: device-width;}  (0) 2020.04.13
CSS: flexbox  (0) 2020.04.07
Comments