๊ฐœ๋ฐœ ๐Ÿพ/HTML,CSS

CSS ํŒจํ„ด ์ด์•ผ๊ธฐ - BEM, SMACSS, OOCSS

JOTOKKI 2021. 2. 7. 19:30
728x90

 

1. SMACSS ( Scalable and Modular Architecture for CSS )

: CSS๋ฅผ [๊ธฐ๋ณธ(base), ๋ ˆ์ด์•„์›ƒ(layout), ๋ชจ๋“ˆ(module), ์ƒํƒœ(state), ํ…Œ๋งˆ(theme)]5๊ฐ€์ง€๋ฅผ ๋ฒ”์ฃผํ™”๋กœ ํŒจํ„ดํ™” ํ•˜๊ณ ์ž ํ•จ = categorization

 

1. Base.css [= reset.css]

body, p, table, form, fieldset, legend, input, button ... {
    margin: 0;
    padding: 0;
}

2. layout : ์ฃผ์š”์†Œ(id) + ํ•˜์œ„์š”์†Œ(class)

์˜ˆ : 2๊ฐœ์˜ ๋ ˆ์ด์›ƒ ์Šคํƒ€์ผ์„ ์‚ฌ์šฉํ• ๊ฒฝ์šฐ [ 1.์œ ์—ฐํ•œ๋ ˆ์ด์•„์›ƒ 2.๊ณ ์ •์ ๋ ˆ์ด์•„์›ƒ ]

#header {
    width: 400px;
}
#aside {
    width: 30px;
}
// ํ•˜์œ„ ์š”์†Œ
.l-width #header {
    width: 600px;
    padding: 10px;
}
.l-width #aside {
    width: 100px
}

3. module : ์žฌ์‚ฌ์šฉ๊ฐ€๋Šฅํ•œ ์š”์†Œ

.title{...}
.title-sub{...}
.title-pop{...}

4. state : ์š”์†Œ์˜ ์ƒํƒœ๋ณ€ํ™”๋ฅผ ํ‘œํ˜„

.is-error { ... }
.is-hidden { ... }
.is-disabled { ... }

// another Ex
.tab {
    background-color: purple;
    color: white;
}

.is-tab-active {
    background-color: white;
    color: black;
}

5. theme : ์„ ํƒ์ ์œผ๋กœ ์Šคํƒ€์ผ ์žฌ์„ ์–ธ ( suffix ์— li- ๋ฅผ ๋ถ™์—ฌ์„œ ์‚ฌ์šฉ )

// in module-name.css
.mod {
    border: 1px solid;
}
// in theme.css
.mod {
    border-color: blue;
}

๊ณต์‹์‚ฌ์ดํŠธ : http://smacss.com/book/type-theme

 


 

2. BEM( Block, Element, Modifier ) / ๋ธ”๋ก, ์š”์†Œ, ์ˆ˜์ •

1. Block

: ์žฌ์‚ฌ์šฉ๊ฐ€๋Šฅํ•œ ์˜์—ญ๋“ค [ header, footer, navigation... ] ์ด๋ฉฐ, ์ข…์†๋˜์ง€์•Š๋Š” ๋…๋ฆฝ์ ์ธ ํ•˜๋‚˜์˜ ์ƒํƒœ.

ํ•˜๋‚˜์˜ ๋‹จ์–ด๋ฅผ ์‚ฌ์šฉํ•˜๋˜ ๊ธธ์–ด์งˆ๊ฒฝ์šฐ -๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค

 

.head{...}
.block{...}

.header-navigation{...}
.header-popup{...}

 

2. Element

: Block์˜ ๋‚ด๋ถ€ ๊ตฌ์„ฑ์„ ํ‘œํ˜„, ๋‘๊ฐœ์˜ underscores๋กœ ํ‘œ๊ธฐํ•˜๋ฉฐ ์†์„ฑ์„ ํ”ผํ•ด์„œ ์‚ฌ์šฉ

"๋ธ”๋ก์ด๋ฆ„__์š”์†Œ์ด๋ฆ„" ์œผ๋กœ ํ‘œ๊ธฐ

 

.header { ... }
.block__elem { color: #042; }

// NOT GOOD
.block .block__elem { color: #042; }
div.block__elem { color: #042; }

 

3. Modifier : ๋ณ€ํ• ์ˆ˜ ์žˆ๋Š” ๋ธ”๋Ÿญ์ด๋‚˜ ์š”์†Œ์˜ ์ƒํƒœ ๋‘๊ฐœ์˜ hyphen(--)์œผ๋กœ ํ‘œ๊ธฐ

"๋ธ”๋ก์ด๋ฆ„--์ƒํƒœ", "๋ธ”๋ก์ด๋ฆ„__์š”์†Œ์ด๋ฆ„--์ƒํƒœ" ์œผ๋กœ ํ‘œ๊ธฐ

 

.block--hidden { ... }
.block__elem--mod { ... }

 

๋‹จ์  : ์ฝ”๋“œ๋ฅผ ์ง๊ด€์ ์œผ๋กœ ํŒŒ์•…ํ•˜๊ธฐ ์ข‹์œผ๋‚˜ ์ด๋ฆ„์ด ๊ธธ๊ณ  ๋ณต์žกํ•ด์งˆ์ˆ˜์žˆ์Œ

 

๊ณต์‹์‚ฌ์ดํŠธ : http://getbem.com/

 


 

3. OOCSS(Object Oriented CSS)

: ์ค‘๋ณต์„ ์ตœ์†Œํ™”,์บก์Šํ™”

: ์ปจํ…Œ์ด๋„ˆ, ์ปจํ…์ธ  ๋ถ„๋ฆฌ

 

<div class="header common-width">Header</div>
<div class="footer common-width">Footer</div>

.header{
    position: fixed;
    top: 0;
}
.footer{
    position: absolute;
    bottom: 0;
}
.common-width{
    width: 700px;
    margin: 0;
}

: ๊ตฌ์กฐ ๋ชจ์–‘ ๋ถ„๋ฆฌ, ๊ฒฐํ•จ

<div class="btn skin tel">tel</div>
<div class="btn skin">email</div>
.btn{๊ณตํ†ต ์Šคํƒ€์ผ ์ •์˜}
.skin{๊ณตํ†ต ์Šคํƒ€์ผ ์ •์˜}

๋‹จ์  : ์žฌํ™œ์šฉ์„ฑ ๋†’์•„์ง, ๋‹ค์ค‘ํด๋ž˜์Šค๋กœ ์ธํ•œ ์œ ์ง€๋ณด์ˆ˜์˜ ์–ด๋ ค์›€๊ณผ ๋ณต์žก๋„ ์ƒ์Šน

๊ณต์‹์‚ฌ์ดํŠธ : http://oocss.org/

 


* ๊ฒฐ๋ก 

* 3๊ฐ€์ง€ ๋ฐฉ๋ฒ•๋ก ์ด ์ง€ํ–ฅํ•˜๋Š” ์ 

 

1. ์ฝ”๋“œ์˜ ์žฌ์‚ฌ์šฉ์„ฑ

2. ์‰ฌ์šด ์œ ์ง€๋ณด์ˆ˜(ํšจ์œจ์„ฑ)

3. ํ™•์žฅ๊ฐ€๋Šฅ์„ฑ

4. ๊ตฌ์กฐ, ์Šคํ‚จ ๋ถ„ํ• 

 

* 3๊ฐ€์ง€ ๋ฐฉ๋ฒ•๋ก ์ด ์ง€์–‘ํ•˜๋Š” ์ 

1. ์˜์กด์ ์ธ ์Šคํƒ€์ผ [ .class p{...} ]

2. Tag ์ง์ ‘ ์ ‘๊ทผ [ div.class{...} ]

 

** ์ฐธ์กฐ

https://medium.com/@jinminkim_50502/css-bem-smacss-oocss-9e4d6beb0a38

https://wit.nts-corp.com/2015/04/16/3538

 

๋ฐ˜์‘ํ˜•