๋ณธ๋ฌธ์œผ๋กœ ๊ฑด๋„ˆ๋›ฐ๊ธฐ

Syntax-10-built-in-functions

Sass(SCSS) Syntax - 10. ๋‚ด์žฅ ํ•จ์ˆ˜(Built-in Functions)#

โ—๏ธ ํ•ด๋‹น ๊ธ€์€ ํŒจ์ŠคํŠธ์บ ํผ์Šค - ํ”„๋ก ํŠธ์—”๋“œ ๊ฐœ๋ฐœ ๊ฐ•์˜์—์„œ HTML & CSS, SASS(SCSS) Part์˜ ๋ฐ•์˜์›… ๊ฐ•์‚ฌ๋‹˜์˜ ๊ฐ•์˜์ž๋ฃŒ(Sass(SCSS) ์™„์ „ ์ •๋ณต!)๋ฅผ ๋ณด๋ฉฐ ์ •๋ฆฌํ•œ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

๋‚ด์žฅ ํ•จ์ˆ˜(Built-in Functions)#

Sass์—์„œ ๊ธฐ๋ณธ์ ์œผ๋กœ ์ œ๊ณตํ•˜๋Š” ๋‚ด์žฅ ํ•จ์ˆ˜์—๋Š” ๋งŽ์€ ์ข…๋ฅ˜๊ฐ€ ์žˆ๋‹ค.

Sass Built-in Functions์—์„œ ๋ชจ๋“  ๋‚ด์žฅ ํ•จ์ˆ˜๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Œ

  • []๋Š” ์„ ํƒ ๊ฐ€๋Šฅํ•œ ์ธ์ˆ˜(argument)

  • Zero-based numbering์„์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค.

์ƒ‰์ƒ(RGB / HSL / Opacity) ํ•จ์ˆ˜#

mix($color1, $color2) : ๋‘ ๊ฐœ์˜ ์ƒ‰์„ ํ˜ผํ•ฉ

lighten($color, $amount) : ๋” ๋ฐ์€์ƒ‰

darken($color, $amount) : ๋” ์–ด๋‘์šด์ƒ‰

saturate($color, $amount) : ์ƒ‰์ƒ์˜ ์ฑ„๋„๋ฅผ ๋†’์ž„

desaturate($color, $amount) : ์ƒ‰์ƒ์˜ ์ฑ„๋„๋ฅผ ๋‚ฎ์ถค

grayscale(\$color) : ์ƒ‰์ƒ์„ ํšŒ์ƒ‰์œผ๋กœ ๋ณ€ํ™˜

invert(\$color) : ์ƒ‰์ƒ์„ ๋ฐ˜์ „

rgba($color, $alpha) : ์ƒ‰์ƒ์˜ ํˆฌ๋ช…๋„ ๋ณ€๊ฒฝ

opacify(\$color, amount )/fade โ€…โˆ’โ€…in (color, \$amount) : ์ƒ‰์ƒ์„ ๋” ๋ถˆํˆฌ๋ช…ํ•˜๊ฒŒ

transparentize(\$color, amount )/fade โ€…โˆ’โ€…out (color, \$amount) : ์ƒ‰์ƒ์„ ๋” ํˆฌ๋ช…ํ•˜๊ฒŒ

๋ฌธ์ž(String) ํ•จ์ˆ˜#

unquote(\$string) : ๋ฌธ์ž์˜ ๋”ฐ์˜ดํ‘œ ์ œ๊ฑฐ

quote(\$string) : ๋ฌธ์ž์— ๋”ฐ์˜ดํ‘œ ์ถ”๊ฐ€

str-insert($string, $insert, \$index) : ๋ฌธ์ž์˜ index๋ฒˆ์งธ์— ํŠน์ • ๋ฌธ์ž๋ฅผ ์‚ฝ์ž…

str-index($string, $substring) : ๋ฌธ์ž์—์„œ ํŠน์ • ๋ฌธ์ž์˜ ์ฒซ index๋ฅผ ๋ฐ˜ํ™˜

str-slice(\$string, start โ€…โˆ’โ€…at ,โ€†[end-at]) : ๋ฌธ์ž์—์„œ ํŠน์ • ๋ฌธ์ž(๋ช‡ ๋ฒˆ์งธ ๊ธ€์ž๋ถ€ํ„ฐ ๋ช‡ ๋ฒˆ์งธ ๊ธ€์ž๊นŒ์ง€)๋ฅผ ์ถ”์ถœ

to-upper-case(\$string) : ๋ฌธ์ž๋ฅผ ๋Œ€๋ฌธ์ž๋กœ ๋ณ€ํ™˜

to-lower-case(\$string) : ๋ฌธ์ž๋ฅผ ์†Œ๋ฌธ์ž๋กœ ๋ณ€ํ™˜

์ˆซ์ž(Number) ํ•จ์ˆ˜#

percentage(\$number) : ์ˆซ์ž(๋‹จ์œ„ ๋ฌด์‹œ)๋ฅผ ๋ฐฑ๋ถ„์œจ๋กœ ๋ณ€ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

round(\$number) : ์ •์ˆ˜๋กœ ๋ฐ˜์˜ฌ๋ฆผํ•ฉ๋‹ˆ๋‹ค.

ceil(\$number) : ์ •์ˆ˜๋กœ ์˜ฌ๋ฆผํ•ฉ๋‹ˆ๋‹ค.

floor(\$number) : ์ •์ˆ˜๋กœ ๋‚ด๋ฆผ(๋ฒ„๋ฆผ)ํ•ฉ๋‹ˆ๋‹ค.

abs(\$number) : ์ˆซ์ž์˜ ์ ˆ๋Œ€ ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

min(\$numbersโ€ฆ) : ์ˆซ์ž ์ค‘ ์ตœ์†Œ ๊ฐ’์„ ์ฐพ์Šต๋‹ˆ๋‹ค.

max(\$numbersโ€ฆ) : ์ˆซ์ž ์ค‘ ์ตœ๋Œ€ ๊ฐ’์„ ์ฐพ์Šต๋‹ˆ๋‹ค.

random() : 0 ๋ถ€ํ„ฐ 1 ์‚ฌ์ด์˜ ๋‚œ์ˆ˜๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

List ํ•จ์ˆ˜#

๋ชจ๋“  List ๋‚ด์žฅ ํ•จ์ˆ˜๋Š” ๊ธฐ์กด List ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐฑ์‹ ํ•˜์ง€ ์•Š๊ณ  ์ƒˆ List ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ๋ชจ๋“  List ๋‚ด์žฅ ํ•จ์ˆ˜๋Š” Map ๋ฐ์ดํ„ฐ์—์„œ๋„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

length(\$list) : List์˜ ๊ฐœ์ˆ˜๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

nth($list, $n) : List์—์„œ n๋ฒˆ์งธ ๊ฐ’์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

set-nth($list, $n, \$value) : List์—์„œ n๋ฒˆ์งธ ๊ฐ’์„ ๋‹ค๋ฅธ ๊ฐ’์œผ๋กœ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค.

join(\$list1, list2,โ€†[separator]) : ๋‘ ๊ฐœ์˜ List๋ฅผ ํ•˜๋‚˜๋กœ ๊ฒฐํ•ฉํ•ฉ๋‹ˆ๋‹ค.

zip(\$listsโ€ฆ) : ์—ฌ๋Ÿฌ List๋“ค์„ ํ•˜๋‚˜์˜ ๋‹ค์ฐจ์› List๋กœ ๊ฒฐํ•ฉํ•ฉ๋‹ˆ๋‹ค.

index($list, $value) : List์—์„œ ํŠน์ • ๊ฐ’์˜ index๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

Map ํ•จ์ˆ˜#

๋ชจ๋“  Map ๋‚ด์žฅ ํ•จ์ˆ˜๋Š” ๊ธฐ์กด Map ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐฑ์‹ ํ•˜์ง€ ์•Š๊ณ  ์ƒˆ Map ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

map-get($map, $key) : Map์—์„œ ํŠน์ • key์˜ value๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

map-merge($map1, $map2) : ๋‘ ๊ฐœ์˜ Map์„ ๋ณ‘ํ•ฉํ•˜์—ฌ ์ƒˆ๋กœ์šด Map๋ฅผ ๋งŒ๋“ญ๋‹ˆ๋‹ค.

map-keys(\$map) : Map์—์„œ ๋ชจ๋“  key๋ฅผ List๋กœ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

map-values(\$map) : Map์—์„œ ๋ชจ๋“  value๋ฅผ List๋กœ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

๊ด€๋ฆฌ(Introspection) ํ•จ์ˆ˜#

variable-exists(name) : ๋ณ€์ˆ˜๊ฐ€ ํ˜„์žฌ ๋ฒ”์œ„์— ์กด์žฌํ•˜๋Š”์ง€ ์—ฌ๋ถ€๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.(์ธ์ˆ˜๋Š” $์—†์ด ๋ณ€์ˆ˜์˜ ์ด๋ฆ„๋งŒ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.)

unit(\$number) : ์ˆซ์ž์˜ ๋‹จ์œ„๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

unitless(\$number) : ์ˆซ์ž์— ๋‹จ์œ„๊ฐ€ ์žˆ๋Š”์ง€ ์—ฌ๋ถ€๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

comparable($number1, $number2) : ๋‘ ๊ฐœ์˜ ์ˆซ์ž๊ฐ€ ์—ฐ์‚ฐ ๊ฐ€๋Šฅํ•œ์ง€ ์—ฌ๋ถ€๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

Reference#

ํŒจ์ŠคํŠธ์บ ํผ์Šค - ํ”„๋ก ํŠธ์—”๋“œ ๊ฐœ๋ฐœ ๊ฐ•์˜ - HTML & CSS, SASS(SCSS) Part by ParkYoungWoong

Sass(SCSS) ์™„์ „ ์ •๋ณต!

Sass Built-in Functions

Zero-based numbering