Go๋ฏผ๋ณด๋‹ค Go

ํ”„๋ก ํŠธ์—”๋“œ ๊ฐœ๋ฐœ์ž

Read

[CSS] ์›น ์Šคํƒ€์ผ๋ง

SleepingOff 2024. 5. 3. 17:43

๐Ÿพ๋“ค์–ด๊ฐ€๋ฉฐ

CSS ๊ด€๋ จํ•ด์„œ ์—ฌ๋Ÿฌ ๊ฐ€์ง€๋ฅผ ์‚ฌ์šฉํ•ด๋ณด๋Š”๋ฐ, ์–ด๋–ค ์ฐจ์ด๊ฐ€ ์žˆ๋Š”์ง€ ๊ฐ„๋‹จํ•˜๊ฒŒ ๊ตฌ๋ถ„ํ•ด๋ณด๋ ค๊ณ  ๊ธ€์„ ์”๋‹ˆ๋‹ค.

โœจ๋ณธ๊ฒฉ์ ์œผ๋กœ

โœ…CSS, module, SCSS, CSS in JS...

CSS: ์›น ๋ฌธ์„œ์˜ ๋””์ž์ธ์„ ์”Œ์šธ ์ˆ˜ ์žˆ๊ฒŒ ๋งŒ๋“œ๋Š” ์Šคํƒ€์ผ ์‹œํŠธ.
-> ๋Œ€๊ทœ๋ชจ ํ”„๋กœ์ ํŠธ์—์„œ ์ „์—ญ์ ์œผ๋กœ ์ ์šฉ๋˜๋Š” CSS๋Š” ๊ด€๋ฆฌ์˜ ์–ด๋ ค์›€์ด ์žˆ๋‹ค.

selecorA {
    /*...css...*/
} 

selectorB.class {
    /*...css...*/
}

CSS-module: style.module.css ์ฒ˜๋Ÿผ CSS๋ฅผ moduleํ™”ํ•˜์—ฌ ์‚ฌ์šฉ
-> ์ค‘๋ณต๋˜๋Š” ํด๋ž˜์Šค๋ช…์ด์–ด๋„ ๊ณ ์œ ํ•œ hash ๊ฐ’์ด ํด๋ž˜์Šค๋ช…์— ๋ถ™๊ธฐ ๋•Œ๋ฌธ์— ๋‹ค๋ฅธ ์Šคํƒ€์ผ๋กœ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค.

selecor {
    /*...css...*/
} 

selector.class {
    /*...css...*/
}

SCSS: CSS์—์„œ ์ฝ”๋“œ์˜ ๊ฐ€๋…์„ฑ์„ ํ–ฅ์ƒํ•˜๊ณ , ์žฌ์‚ฌ์šฉ์„ฑ์„ ๋†’์ด๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉํ•˜๋Š” ์ „์ฒ˜๋ฆฌ๊ธฐ
-> Sass์˜ 3๋ฒ„์ „์—์„œ ์ƒˆ๋กญ๊ฒŒ ๋“ฑ์žฅํ•œ SCSS. Sass์˜ ๋ชจ๋“  ๊ธฐ๋Šฅ์„ ์ง€์›ํ•˜๋Š” CSS์˜ ์ƒ์œ„์ง‘ํ•ฉ.

@import './shared.scss';

selecor {
    /*...css...*/
    &.class {
        /*...css...*/
    }
}

@mixin border-radius($radius) {
    -webkit-border-radius: $radius;
    -moz-border-radius: $radius;
    -ms-border-radius: $radius;
    border-radius: $radius;
}

.class { @include border-radius(10px); }

CSS in JS: ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‚ฌ์šฉํ•ด CSS๋ฅผ ์ ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.
-> React์™€ ์‚ฌ์ด๊ฐ€ ์ข‹๋‹ค. ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋งŒ๋“œ๋Š” ๋ฐฉ์‹์œผ๋กœ ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•˜๊ธฐ ๋•Œ๋ฌธ์—.
๋Œ€ํ‘œ์ ์œผ๋กœ styled-components์™€ emotion์ด ์žˆ๋‹ค.

const Box = styled.div`
    //...css...
`
<Box/>

-> vue์˜ style scoped: module๊ณผ ๋น„์Šทํ•˜์ง€๋งŒ, ํ•˜๋‚˜์˜ ์ปดํฌ๋„ŒํŠธ์—์„œ ์ ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•œ๋‹ค.
data ์†์„ฑ๊ฐ’์„ ์‚ฌ์šฉํ•ด css ์„ ํƒ์ž๋ฅผ ๋ณ€๊ฒฝํ•˜๋Š” ๊ฒƒ.

โœ”๏ธ๊ฒฐ๋ก 

์ด๋ ‡๊ฒŒ ๊นŒ์ง€ ์ ๊ณ  ๋‚˜๋‹ˆ ์—ฌ๊ธฐ์—์„œ ๋ฌด์—‡์„ ๋” ์•Œ์•„์•ผ ์ข‹์„๊นŒ ํ•˜๋Š” ๊ณ ๋ฏผ๊ณผ ๋” ์ด์ƒ ๊ธ€์ด ์ด์–ด์ง€์ง€ ์•Š์•„์„œ ๋งˆ๋ฌด๋ฆฌํ•ฉ๋‹ˆ๋‹ค...!

728x90