CSS Property에는 키워드, 크기 단위, 색상 표현 등의 특정 단위를 갖는 값을 지정함
<!DOCTYPE html>
<html>
<head>
<style>
body {
text-align: center;
}
div {
font-size: 14px;
font-weight: bold;
padding: 2em; /*2em = 14px * 2 = 28px */
background-color: rgba(255, 0, 0, 0.2) /*rgba(red, green, blue, alpha)*/
}
</style>
</head>
<body>
<div>Font size: 14px</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-size: 14px;
text-align: center;
}
div {
font-size: 120%; /* 14px * 1.2 = 16.8px */
font-weight: bold;
padding: 2em; /*2em = 16.8px * 2 = 33.6px */
background-color: rgba(255, 0, 0, 0.2)
}
</style>
</head>
<body>
<div>Font size: 14px * 120% = 16.8px</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-size: 14px;
text-align: center;
}
div {
font-size: 1.2em; /* 14px * 1.2 = 16.8px */
font-weight: bold;
padding: 2em; /*2em = 16.8px * 2 = 33.6px */
background-color: rgba(255, 0, 0, 0.2)
}
</style>
</head>
<body>
<div>Font size: 1.2em = 14px * 1.2 = 16.8px</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-size: 14px;
text-align: center;
}
div {
font-size: 1.2em; /* 14px * 1.2 = 16.8px */
font-weight: bold;
padding: 2em;
}
.box1 { background-color: rgba(255, 0, 0, 0.2); }
.box2 { background-color: rgba(255, 0, 0, 0.4); }
.box3 { background-color: rgba(255, 0, 0, 0.8); }
</style>
</head>
<body>
<div class='box1'>
Font size: 1.2em = 14px * 1.2 = 16.8px
<div class='box2'>
Font size: 1.2em = 16.8px * 1.2 = 20.16px
<div class='box3'>
Font size: 1.2em = 20.16px * 1.2 = 24.192px
</div>
</div>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-size: 14px;
/* font-size 미지정 시에는 16px */
}
div {
font-size: 1.2rem; /* 14px(html font-size) * 1.2 = 16.8px */
font-weight: bold;
padding: 2em;
text-align: center;
}
.box1 { background-color: rgba(255, 0, 0, 0.2); }
.box2 { background-color: rgba(255, 0, 0, 0.4); }
.box3 { background-color: rgba(255, 0, 0, 0.8); }
</style>
</head>
<body>
<div class='box1'>
Font size: 1.2rem = 14px * 1.2 = 16.8px
<div class='box2'>
Font size: 1.2rem = 14px * 1.2 = 16.8px
<div class='box3'>
Font size: 1.2rem = 14px * 1.2 = 16.8px
</div>
</div>
</div>
</body>
</html>
.container {
width: 70rem; /* 70rem = 14px * 70 = 980px */
}
단위 | discription |
---|---|
vw | viewpoint 너비의 1/100 |
vh | viewpoint 높이의 1/100 |
vmin | viewpoint 너비 또는 높이 중 작은 쪽의 1/100 |
vmax | viewpoint 너비 또는 높이 중 큰 쪽의 1/100 |
예) viewpoint 너비 1000px, 높이 600px일 때,
IE8 이하 지원 X, IE 9~11, Edge 지원 불완전함
<!DOCTYPE html>
<html>
<head>
<style>
body { margin: opx; }
.item {
width: 50vw;
height: 100vh;
text-align: center;
line-height: 100vh;
font-size: 4rem;
color: white;
}
.item1 { background-color: red; }
.item2 { background-color: orange; }
</style>
</head>
<body>
<div class='item item1'>item1</div>
<div class='item item2'>item2</div>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<h2 style="background-color:red">
Red background color
</h2>
<h2 style="background-color:green">
Green background color
</h2>
<h2 style="background-color:blue; color:white">
Blue background color and white text color
</h2>
<h2 style="background-color:orange">
Orange background color
</h2>
<h2 style="background-color:yellow">
Yellow background color
</h2>
<h2 style="background-color:cyan">
Cyan background color
</h2>
<h2 style="background-color:black; color:white">
Black background color and white text color
</h2>
</body>
</html>
단위 | 사용 예 |
---|---|
HEX 단위 코드 (Hexademical Colors) | #000000 |
RGB (Red, Green, Blue) | rgb(255, 255, 0) |
RGBA (Red, Green, Blue, Alpha) | rgba(255, 255, 0, 1) |
HSL (Hue 색상, Saturation 채도, Light 명도) | hsl(0, 100%, 25%) |
HSLA (Hue, Saturation, Light, Alpha) | hsla(60, 100%, 25%, 1) |
<!DOCTYPE html>
<html>
<head>
<style>
#hex-p1 { background-color: #ff0000; }
#hex-p2 { background-color: #00ff00; }
#hex-p3 { background-color: #0000ff; }
#hex-p4 { background-color: #ffff00; }
#hex-p5 { background-color: #ff00ff; }
#rgb-p1 { background-color: rgb(255,0,0); }
#rgb-p2 { background-color: rgb(0,255,0); }
#rgb-p3 { background-color: rgb(0,0,255); }
#rgb-p4 { background-color: rgb(192,192,192); }
#rgb-p5 { background-color: rgb(255,255,0); }
#rgb-p6 { background-color: rgb(255,0,255); }
#rgba-p1 { background-color: rgba(255,0,0,0.3); }
#rgba-p2 { background-color: rgba(0,255,0,0.3); }
#rgba-p3 { background-color: rgba(0,0,255,0.3); }
#rgba-p4 { background-color: rgba(192,192,192,0.3); }
#rgba-p5 { background-color: rgba(255,255,0,0.3); }
#rgba-p6 { background-color: rgba(255,0,255,0.3); }
#hsl-p1 { background-color: hsl(120,100%,50%)}
#hsl-p2 { background-color: hsl(120,100%,75%)}
#hsl-p3 { background-color: hsl(120,100%,25%)}
#hsl-p4 { background-color: hsl(120,60%,70%)}
#hsl-p5 { background-color: hsl(290,100%,50%)}
#hsl-p6 { background-color: hsl(290,60%,70%)}
#hsla-p1 { background-color: hsla(120,100%,50%,0.3)}
#hsla-p2 { background-color: hsla(120,100%,75%,0.3)}
#hsla-p3 { background-color: hsla(120,100%,25%,0.3)}
#hsla-p4 { background-color: hsla(120,60%,70%,0.3)}
#hsla-p5 { background-color: hsla(290,100%,50%,0.3)}
#hsla-p6 { background-color: hsla(290,60%,70%,0.3)}
</style>
</head>
<body>
<h1>HEX colors:</h1>
<p id="hex-p1">Red</p>
<p id="hex-p2">Green</p>
<p id="hex-p3">Blue</p>
<p id="hex-p4">Yellow</p>
<p id="hex-p5">Cerise</p>
<h1>RGB colors:</h1>
<p id="rgb-p1">Red</p>
<p id="rgb-p2">Green</p>
<p id="rgb-p3">Blue</p>
<p id="rgb-p4">Gray</p>
<p id="rgb-p5">Yellow</p>
<p id="rgb-p6">Cerise</p>
<h1>RGB colors with opacity:</h1>
<p id="rgba-p1">Red</p>
<p id="rgba-p2">Green</p>
<p id="rgba-p3">Blue</p>
<p id="rgba-p4">Gray</p>
<p id="rgba-p5">Yellow</p>
<p id="rgba-p6">Cerise</p>
<h1>HSL colors:</h1>
<p id="hsl-p1">Green</p>
<p id="hsl-p2">Light Green</p>
<p id="hsl-p3">Dark Green</p>
<p id="hsl-p4">Pastel Green</p>
<p id="hsl-p5">Violet</p>
<p id="hsl-p6">Pastel Violet</p>
<h1>HSL colors with opacity:</h1>
<p id="hsla-p1">Green</p>
<p id="hsla-p2">Light Green</p>
<p id="hsla-p3">Dark Green</p>
<p id="hsla-p4">Pastel Green</p>
<p id="hsla-p5">Violet</p>
<p id="hsla-p6">Pastel Violet</p>
</body>
</html>