10-1. CSS ๋ฐ˜์‘ํ˜• ์›น, ๋ทฐํฌํŠธ, ๋ฏธ๋””์–ด์ฟผ๋ฆฌ, ๋ฏธ๋””์–ด ์ฟผ๋ฆฌ ์œ ์šฉํ•œ ์‚ฌ์ดํŠธ

2021. 10. 17. 12:42ใ†HTML + CSS + JS

728x90

1. ๋ฐ˜์‘ํ˜• ์›น

๋ฐ˜์‘ํ˜• ์›น ๋””์ž์ธ์€ ์›น ์š”์†Œ๋ฅผ ํ™”๋ฉด ํฌ๊ธฐ์— ๋งž๊ฒŒ ์žฌ๋ฐฐ์น˜ํ•˜๊ณ  ๊ฐ ์š”์†Œ์˜ ํ‘œ์‹œ ๋ฐฉ๋ฒ•๋งŒ ๋ฐ”๊พธ์–ด ์‚ฌ์ดํŠธ๋ฅผ ๊ตฌํ˜„ํ•˜๋Š” ๊ฒƒ์ด๋‹ค. 

 

2. ๋ทฐํฌํŠธ

๋ทฐํฌํŠธ viewport ๋ž€ ์Šค๋งˆํŠธํฐ ํ™”๋ฉด์—์„œ ์‹ค์ œ ๋‚ด์šฉ์ด ํ‘œ์‹œ๋˜๋Š” ์˜์—ญ์ด๋‹ค. 

๋ทฐํฌํŠธ๋Š” <head> ํƒœ๊ทธ ์‚ฌ์ด์— <meta> ํƒœ๊ทธ๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์ž‘์„ฑํ•œ๋‹ค. 

<meta name = "viewport" content ="์†์„ฑ1= ๊ฐ’1",..>

๋ทฐํฌํŠธ ๋‹จ์œ„ 

1๏ธโƒฃ vw(viewport width) : 1vw๋Š” ๋ทฐํฌํŠธ ๋„ˆ๋น„์˜ 1%

2๏ธโƒฃ vh(viewport height) : 1vh๋Š” ๋ทฐํฌํŠธ ๋†’์ด์˜ 1%

3๏ธโƒฃ vmin (viewport minimum) : ๋ทฐํฌํŠธ ๋„ˆ๋น„์™€ ๋†’์ด ์ค‘์—์„œ ์ž‘์€ ๊ฐ’์˜ 1% 

4๏ธโƒฃ vmax (viewport maximum) : ๋ทฐํฌํŠธ ๋„ˆ๋น„์™€ ๋†’์ด ์ค‘์—์„œ ํฐ ๊ฐ’์˜ 1% 

 

 

3. ๋ฏธ๋””์–ด์ฟผ๋ฆฌ 

CSS๋ชจ๋“ˆ์ธ ๋ฏธ๋””์–ด ์ฟผ๋ฆฌ๋Š” ์‚ฌ์ดํŠธ์— ์ ‘์†ํ•˜๋Š” ์žฅ์น˜์— ๋”ฐ๋ผ ํŠน์ •ํ•œ CSS ์Šคํƒ€์ผ์„ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค. 

๋ฏธ๋””์–ด ์ฟผ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์ ‘์†ํ•˜๋Š” ๊ธฐ๊ธฐ์˜ ํ™”๋ฉด ํฌ๊ธฐ์— ๋”ฐ๋ผ ๋ ˆ์ด์•„์›ƒ์ด ๋‹ฌ๋ผ์ง„๋‹ค. 

์ฆ‰ ์‚ฌ์šฉ์ž๊ฐ€ ์–ด๋–ค ๋ฏธ๋””์–ด๋ฅผ ์‚ฌ์šฉํ•˜๋Š”๊ฐ€์— ๋”ฐ๋ผ ์‚ฌ์ดํŠธ์˜ ํ˜•ํƒœ๊ฐ€ ๋ฐ”๋€Œ๋„๋ก CSS๋ฅผ ์ž‘์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ๋ฏธ๋””์–ด ์ฟผ๋ฆฌ๋ผ๊ณ  ํ•œ๋‹ค. 

@media [only | not] ๋ฏธ๋””์–ด ์œ ํ˜• [and ์กฐ๊ฑด] * [and ์กฐ๊ฑด]

-> only : ๋ฏธ๋””์–ด ์ฟผ๋ฆฌ๋ฅผ ์ง€์›ํ•˜์ง€ ์•Š๋Š” ์›น ๋ธŒ๋ผ์šฐ์ €๋Š” ๋ฏธ๋””์–ด ์ฟผ๋ฆฌ๋ฅผ ๋ฌด์‹œํ•˜๊ณ  ์‹คํ–‰ํ•˜์ง€ ์•Š๋Š”๋‹ค. 

-> not : ๋‹ค์Œ์— ์ง€์ •ํ•˜๋Š” ๋ฏธ๋””์–ด ์œ ํ˜•์„ ์ œ์™ธํ•œ๋‹ค. 

 

1๏ธโƒฃ ๋ฏธ๋””์–ด ์œ ํ˜•์˜ ์ข…๋ฅ˜ 

all : ๋ชจ๋“  ๋ฏธ๋””์–ด ์œ ํ˜•์—์„œ ์‚ฌ์šฉํ•  css๋ฅผ ์ •์˜ํ•œ๋‹ค. 

print : ์ธ์‡„์žฅ์น˜์—์„œ ์‚ฌ์šฉํ•  css๋ฅผ ์ •์˜ํ•œ๋‹ค. 

screen : ์ปดํ“จํ„ฐ ์Šคํฌ๋ฆฐ์—์„œ ์‚ฌ์šฉํ•  css๋ฅผ ์ •์˜ํ•˜๊ณ , ์Šค๋งˆํŠธํฐ ์Šคํฌ๋ฆฐ๋„ ํฌํ•จ๋œ๋‹ค. 

tv : ์Œ์„ฑ๊ณผ ์˜์ƒ์ด ๋™์‹œ์— ์ถœ๋ ฅ๋˜๋Š” tv์—์„œ ์‚ฌ์šฉํ•  css๋ฅผ ์ •์˜ํ•œ๋‹ค. 

aural : ์Œ์„ฑ ํ•ฉ์„ฑ ์žฅ์น˜์—์„œ ์‚ฌ์šฉํ•  css๋ฅผ ์ •์˜ํ•œ๋‹ค. 

braile : ์ ์ž ํ‘œ์‹œ ์žฅ์น˜์—์„œ ์‚ฌ์šฉํ•  css๋ฅผ ์ •์˜ํ•œ๋‹ค. 

handheld : ํŒจ๋“œ์ฒ˜๋Ÿผ ์†์—์„œ ๋“ค๊ณ  ๋‹ค๋‹ˆ๋Š” ์žฅ์น˜๋ฅผ ์œ„ํ•œ css ๋ฅผ ์ •์˜ํ•œ๋‹ค. 

projection : ํ”„๋กœ์ ํ„ฐ๋ฅผ ์œ„ํ•œ css๋ฅผ ์ •์˜ํ•œ๋‹ค. 

try : ๋””์Šคํ”Œ๋ ˆ์ด ๊ธฐ๋Šฅ์ด ์ œํ•œ๋œ ์žฅ์น˜์— ๋งž๋Š” css๋ฅผ ์ •์˜ํ•œ๋‹ค. 

embossed : ์ ์ž ํ”„๋ฆฐํ„ฐ์—์„œ ์‚ฌ์šฉํ•  css๋ฅผ ์ •์˜ํ•œ๋‹ค. 

 

2๏ธโƒฃ ์›น ๋ฌธ์„œ์˜ ๊ฐ€๋กœ๋„ˆ๋น„์™€ ์„ธ๋กœ ๋†’์ด ์ง€์ • 

width, height : ์›น ํŽ˜์ด์ง€์˜ ๊ฐ€๋กœ ๋„ˆ๋น„, ์„ธ๋กœ ๋†’์ด๋ฅผ ์ง€์ •ํ•œ๋‹ค.

min-width, min-height : ์›น ํŽ˜์ด์ง€์˜ ์ตœ์†Œ ๋„ˆ๋น„, ์ตœ์†Œ ๋†’์ด๋ฅผ ์ง€์ •ํ•œ๋‹ค. 

max-width, max-height: ์›น ํŽ˜์ด์ง€์˜ ์ตœ๋Œ€ ๋„ˆ๋น„, ์ตœ๋Œ€ ๋†’์ด๋ฅผ ์ง€์ •ํ•œ๋‹ค. 

 

3๏ธโƒฃ ๋‹จ๋ง๊ธฐ์˜ ๊ฐ€๋กœ ๋„ˆ๋น„์™€ ์„ธ๋กœ ๋†’์ด ์ง€์ • 

device-width, device-height : ๋‹จ๋ง๊ธฐ์˜ ๊ฐ€๋กœ ๋„ˆ๋น„, ์„ธ๋กœ ๋†’์ด๋ฅผ ์ง€์ •ํ•œ๋‹ค. 

min-device-width, min-deivce-height : ๋‹จ๋ง๊ธฐ์˜ ์ตœ์†Œ ๋„ˆ๋น„, ์ตœ์†Œ ๋†’์ด๋ฅผ ์ง€์ •ํ•œ๋‹ค. 

max-device-width, max-device-height : ๋‹จ๋ง๊ธฐ์˜ ์ตœ๋Œ€ ๋„ˆ๋น„, ์ตœ๋Œ€ ๋†’์ด๋ฅผ ์ง€์ •ํ•œ๋‹ค. 

 

4๏ธโƒฃ ํ™”๋ฉด ํšŒ์ „ ์†์„ฑ 

orientation ์†์„ฑ์„ ์‚ฌ์šฉํ•˜๋ฉด ๊ธฐ๊ธฐ์˜ ๋ฐฉํ–ฅ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

orientation : portrait ๋‹จ๋ง๊ธฐ์˜ ์„ธ๋กœ ๋ชจ๋“œ๋ฅผ ์ง€์ •ํ•œ๋‹ค. 

orientation : landscape  ๋‹จ๋ง๊ธฐ์˜ ๊ฐ€๋กœ ๋ชจ๋“œ๋ฅผ ์ง€์ •ํ•œ๋‹ค. 

 

5๏ธโƒฃ ๋ฏธ๋””์–ด ์ฟผ๋ฆฌ์˜ ์ค‘๋‹จ์  

๋ฏธ๋””์–ด ์ฟผ๋ฆฌ๋ฅผ ์ž‘์„ฑํ•  ๋•Œ ํ™”๋ฉด ํฌ๊ธฐ์— ๋”ฐ๋ผ ์„œ๋กœ ๋‹ค๋ฅธ css๋ฅผ ์ ์šฉํ•  ๋ถ„๊ธฐ์ ์„ ์ค‘๋‹จ์ ์ด๋ผ๊ณ  ํ•œ๋‹ค. 

๋Œ€๋ถ€๋ถ„ ๊ธฐ๊ธฐ์˜ ํ™”๋ฉด ํฌ๊ธฐ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ํ•œ๋‹ค, 

๋ฐ์Šคํฌํ†ฑ : ํ™”๋ฉด ํฌ๊ธฐ๊ฐ€ 1024px ์ด์ƒ์ด๋ฉด ๋ฐ์Šคํฌํ†ฑ์œผ๋กœ ์„ค์ •ํ•œ๋‹ค.

ํƒœ๋ธ”๋ฆฟ : ํ™”๋ฉด ํฌ๊ธฐ๊ฐ€ 768px ์ด์ƒ์ด๋ฉด ํƒœ๋ธ”๋ฆฟ์œผ๋กœ ์ง€์ •ํ•œ๋‹ค. 

https://yesviz.com/devices.php

 

Viewport Size, Resolution, Screen Sizes, CSS PPI and CSS media queries for popular Devices | YesViz

A Useful database contains Viewport Size, Resolution, Screen Sizes, CSS PPI and CSS media queries for popular devices including phones, tablets, smart watches and laptops.

yesviz.com

์—ฌ๊ธฐ ๊ฐ€๋ฉด ๋ฏธ๋””์–ด ์ฟผ๋ฆฌ๋ฅผ ์ž‘์„ฑํ•˜๋Š”๋ฐ ํ•„์š”ํ•œ ๋ทฐ ํฌํŠธ์˜ ํฌ๊ธฐ๊ฐ’์ด ์ •๋ฆฌ๋œ ์‚ฌ์ดํŠธ๋ฅผ ๋ณผ ์ˆ˜ ์žˆ๋‹ค. 

 

4. ๋ฏธ๋””์–ด ์ฟผ๋ฆฌ ์ ์šฉํ•˜๊ธฐ 

 

1๏ธโƒฃ ์™ธ๋ถ€ CSS ํŒŒ์ผ ์—ฐ๊ฒฐํ•˜๊ธฐ 

<link rel = "stylesheet" media = "๋ฏธ๋””์–ด ์ฟผ๋ฆฌ ์กฐ๊ฑด" href = "css ํŒŒ์ผ ๊ฒฝ๋กœ" >

 

@import url (css ํŒŒ์ผ ๊ฒฝ๋กœ) ๋ฏธ๋””์–ด ์ฟผ๋ฆฌ ์กฐ๊ฑด 

 

-> CSS ํŒŒ์ผ์ด ๋งŽ๊ณ  ๊ทœ๋ชจ๊ฐ€ ํฐ ์‚ฌ์ดํŠธ๋ฅผ ๊ฐœ๋ฐœํ•œ๋‹ค๋ฉด <link> ํƒœ๊ทธ๋ฅผ ์ฃผ๋กœ ์‚ฌ์šฉํ•œ๋‹ค. 

 

2๏ธโƒฃ ์›น ๋ฌธ์„œ์— ์ง์ ‘ ์ •์˜ํ•˜๊ธฐ 

<style media = "<์กฐ๊ฑด>" {

  <์Šคํƒ€์ผ ๊ทœ์น™ >

}

</style>

 

<style>

@media <์กฐ๊ฑด> {

  <์Šคํƒ€์ผ ๊ทœ์น™>

}

</style>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

728x90