๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
CSS

[CSS] ๋ฏธ๋””์–ด์ฟผ๋ฆฌ

by _ํ† ๋งคํ†  2022. 8. 16.
728x90

CSS: ๋ฏธ๋””์–ด์ฟผ๋ฆฌ๋ž€?

ํ•ด์ƒ๋„์— ๋”ฐ๋ผ css๋ฅผ ๋ถ„๊ธฐ์‹œํ‚ค๊ธฐ ๋•Œ๋ฌธ์— ๋ฐ˜์‘ํ˜• ํ”„๋กœ์ ํŠธ์—์„œ ๋ฐ˜๋“œ์‹œ ํ•„์š”ํ•œ ๊ธฐ๋ฒ•์ž…๋‹ˆ๋‹ค!


#1. <link ~ media=" ">

<link rel="stylesheet" media="all and (min-width: 1000px)" href="style_pc.css">

!point! ์œ„ ์ฝ”๋“œ๋Š” ์ตœ์†Œ ๊ฐ€๋กœํญ 1000px, ์ฆ‰ 1000px ๋ณด๋‹ค ๋„“์€ ํ•ด์ƒ๋„์ผ ๋•Œ style_pc.css๋ฅผ ์—ฐ๊ฒฐํ•œ๋‹ค๋Š” ๋œป์ž…๋‹ˆ๋‹ค!
๋˜ํ•œ ํฌ๋กฌ ๊ฐœ๋ฐœ์ž ๋„๊ตฌ๋ฅผ ํ†ตํ•ด ๊ฐ ๊ธฐ๊ธฐ๋งˆ๋‹ค์˜ ํ•ด์ƒ๋„์— ๋”ฐ๋ฅธ ์˜ˆ์‹œ๋ฅผ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ํ•ด์ƒ๋„ ํ‰๊ท  ์‚ฌ์ด์ฆˆ ํ‘œ

๊ธฐ๊ธฐ ๊ฐ€๋กœ
๋ฐ์Šคํฌํƒ‘ 1920
ํ…Œ๋ธ”๋ฆฟpc 768
๋ชจ๋ฐ”์ผ 480

#2. @media

์ฒซ ๋กœ๋”ฉ ๋•Œ ์„ฑ๋Šฅ์ด ์ €ํ•˜๋˜์ง€ ์•Š๋„๋ก CSS ํŒŒ์ผ์„ ํ•˜๋‚˜๋กœ ๋งŒ๋“ค์–ด์„œ CSS ๋‚ด๋ถ€์—์„œ ์กฐ๊ฑด์— ๋”ฐ๋ผ ๋ถ„๊ธฐ์‹œํ‚ค๋Š” ๊ฒƒ์ด ์ผ๋ฐ˜์ ์ธ ํ˜•ํƒœ์˜ ๋ฐ˜์‘ํ˜•์›น CSS์ž…๋‹ˆ๋‹ค.

@media all and (min-width: 1000px) {
    /* ๋ชจ๋“  ๊ธฐ๊ธฐ์—์„œ ํ•ด์ƒ๋„๊ฐ€ ์ตœ์†Œ 1000px ์ธ ๊ฒฝ์šฐ ์ ์šฉํ•  ์†์„ฑ๋“ค์„ ์ ์œผ๋ฉด ๋ฉ๋‹ˆ๋‹ค. */
}

๋ฏธ๋””์–ด ํƒ€์ž… ์ข…๋ฅ˜

Media Type ์„ค๋ช…
all ๋ชจ๋“  ๋ฏธ๋””์–ด ์žฅ์น˜์— ์‚ฌ์šฉ (๊ธฐ๋ณธ๊ฐ’)
print ํ”„๋ฆฐํ„ฐ์— ์‚ฌ์šฉ
screen PC, ํƒœ๋ธ”๋ฆฟ, ์Šค๋งˆํŠธํฐ์— ์‚ฌ์šฉ
speech ์Šคํฌ๋ฆฐ๋ฆฌ๋”๊ธฐ๊ฐ€ ํŽ˜์ด์ง€๋ฅผ ์ฝ๋Š”๋ฐ ์‚ฌ์šฉ

!point! and ์–‘ ์˜†์— ๋„์–ด์“ฐ๊ธฐ๋ฅผ ๊ผญ ํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค!

์ฝ”๋“œ ์˜ˆ์ œ

body {
    color: red;    
}

@media only screen and (max-width:768px) {
    body {
        color: blue;
    }
}

์›๋ž˜ ํ•ด์ƒ๋„(pc)ํ•ด์„œ๋Š” ๊ธ€์ž ์ƒ‰์ƒ์ด red์ด์ง€๋งŒ ํ•ด์ƒ๋„๊ฐ€ 768px๋ณด๋‹ค ์ž‘์•„์กŒ์„ ๋•Œ(๋ชจ๋ฐ”์ผ, ํƒœ๋ธ”๋ฆฟ) ๊ธ€์ž ์ƒ‰์ƒ์„ blue๋กœ ์ง€์ •ํ•˜๊ฒ ๋‹ค๋Š” ์˜๋ฏธ ์ž…๋‹ˆ๋‹ค.

@media only screen and (oreientation: portrait) {
    body {
        background: skyblue;
    }
}

๋ชจ๋ฐ”์ผ ๊ธฐ๊ธฐ๊ฐ€ ์„ธ๋กœ ๋ฐฉํ–ฅ์ด ๋˜๋ฉด, ๋ฐฐ๊ฒฝ์ƒ‰์„ ํ•˜๋Š˜์ƒ‰์œผ๋กœ ์„ค์ •ํ•˜๊ฒ ๋‹ค๋Š” ๋œป์ž…๋‹ˆ๋‹ค.

@media only screen and (oreientation: landscape) {
    body {
        background: lightgreen;
    }
}

๋ชจ๋ฐ”์ผ ๊ธฐ๊ธฐ๊ฐ€ ๊ฐ€๋กœ ๋ฐฉํ–ฅ์ด ๋˜๋ฉด, ๋ฐฐ๊ฒฝ์ƒ‰์„ ์—ฐ๋‘์ƒ‰์œผ๋กœ ์„ค์ •ํ•˜๊ฒ ๋‹ค๋Š” ๋œป์ž…๋‹ˆ๋‹ค.


#3. ๋ฏธ๋””์–ด์ฟผ๋ฆฌ ์‹ค์Šตํ•˜๊ธฐ

์ง€๊ธˆ๊นŒ์ง€์˜ ๊ฐœ๋…์„ ๋ฐ”ํƒ•์œผ๋กœ 1280px, 1024px, 768px๋กœ ๋ฏธ๋””์–ด ์ฟผ๋ฆฌ ์‹ค์Šต์„ ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค!

๊ฒฐ๊ณผ๋ณด๊ธฐ

728x90

๋Œ“๊ธ€


Lucky Charms Rainbow
js
html
css