๐ข ๋ฌด์์ด๋ ๊ทธ๋ผ๋ฐ์ด์ ํ๋๋ฒ!
๊ทธ๋ผ๋ฐ์ด์
์ ๋ง๋ค๋ฉด์ ์์๋ ์ํ์ฐฉ์ค๋ค์ ๊ธฐ๋กํ ๊ธ์
๋๋ค.
CSS ์ ์ฉ ๋ฐฉ๋ฒ์ด ๊ถ๊ธํ์ ๋ถ๋ค์ ๊ฐ์ฅ ํ๋จ์ผ๋ก ์ด๋ํด์ฃผ์ธ์!
์์์ ์งํํ๊ณ ์๋ ํ๋ก์ ํธ์์ ๋์์ด๋๋๊ป์ ์ด๋ ๊ฒ ๋ฐฐ๊ฒฝ๋ ๊ทธ๋ผ๋ฐ์ด์ ์ด๊ณ , ์คํธ๋กํฌ์ ๋ฌด๋ ค 3๊ฐ์ ๊ทธ๋ผ๋ฐ์ด์ ์ ๋ฃ์ด๋ฌ๋ผ๋ ์์ฒญ์ด์๋ค. ๊ทธ๋ผ ์ด๊ฑธ ๋ง๋ค๋ฌ ๊ฐ๋ณด์!

๊ธฐ๋ณธ์ ์ธ ์ ํ ๊ทธ๋ผ๋ฐ์ด์ ์ด๋ค. ๋ฐฉํฅ๊ณผ ์ค๋จ์ ์ ์ง์ ํด์ค ์ ์๋ค.
.simple-linear {
background: linear-gradient(blue, pink);
}
.diagonal-gradient {
background: linear-gradient(to bottom right, blue, pink);
}
.angled-gradient {
background: linear-gradient(70deg, blue, pink);
}
.multicolor-linear {
background: linear-gradient(to left, lime 28px, red 77%, cyan);
}

radial gradient๋ ์, ํ์๋ชจ์์ ๊ทธ๋ผ๋ฐ์ด์ ์ ๋ง๋ค๊ธฐ ์ํ์ฌ ์ฌ์ฉ๋๋ค.
1์ฒ๋ผ ํ๋ฉด ์ค์์ ๋ง๋ค์ด์ง๊ณ , 2์ฒ๋ผ ์์์ ์ ์ง์ ํด ์ค ์๋ ์๋ค.
.radial-gradient1 {
background: radial-gradient(cyan 0%, transparent 20%, salmon 40%);
}
.radial-gradient2 {
background: radial-gradient(
farthest-corner at 40px 40px,
#f35 0%,
#43e 100%
);
}

๊ธฐ๋ณธ์ ์ผ๋ก gradient๋ ์์ ๋ถํฌ๋ช
ํ์ง ์์ ์ด์, ์๋์ชฝ gradient๋ ๋ณด์ด๋ ์ํ์ด๋ค. ์ด๋ฅผ ์ํด์๋ rgb, rgba๋ฅผ ์ด์ฉํํฌ๋ช
๋ ์กฐ์ ์ด ํ์ํ๋ค.
.stacked-linear {
background: linear-gradient(
217deg,
rgb(255 0 0 / 80%),
rgb(255 0 0 / 0%) 70.71%
),
linear-gradient(127deg, rgb(0 255 0 / 80%), rgb(0 255 0 / 0%) 70.71%),
linear-gradient(336deg, rgb(0 0 255 / 80%), rgb(0 0 255 / 0%) 70.71%);
}

๊ทธ๋ผ ์ด์ ๋ฌธ๋ฒ์ ์ด์ฉํด์ ํผ๊ทธ๋ง๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ๊ทธ๋ผ๋ฐ์ด์ ์ ํ์ธํ๋ฉฐ ๊ฐ๊ฐ ๋ง๋ ๋ค!
.gradient-background {
background: radial-gradient(farthest-corner at 0 0, rgba(104, 121, 251, 0.4) 0%, rgba(255, 255, 255, 0) 80%);
background: linear-gradient(to bottom right, rgba(104, 121, 251, 0.6), rgba(104, 121, 251, 0)),
background: radial-gradient(farthest-corner at 0% 100%, rgba(255, 255, 255, 0) 0%, rgba(104, 121, 251, 0.25) 100%),
background: linear-gradient(to bottom right, rgba(255, 255, 255, 0.5), rgba(104, 121, 251, 0.3), rgba(255, 255, 255, 0.5));
}

๐จ ์ค๊ฐ ์ด์
์๋ ๋ง์ง๋ง gradient๊ฐ ์๋ radial gradient๋ก ๊ฐ๋ฐํด์ผํ๋๋ฐ ํ๋์ ํฌ๋ช ๋0 โ ํฐ์ ๊ทธ๋ผ๋ฐ์ด์ ์ด ํผ๊ทธ๋ง์์๋ ๋์ค๋๋ฐ, ๊ฐ๋ฐํ๋ฉด์์๋ ์ ์๋ณด์๋ค.
๊ทธ๋์ ๋์์ด๋๋ถ๊ป ํ๋ฝ์ ๋งก๊ณ linear gradient๋ก ๊ฐ๋ฐํ๋ค,,

1์์๋ background๋ฅผ ์ด์ฉํ์ฌ ๋ฐฐ๊ฒฝ์ gradient๋ฅผ ์ ์ฉํ๋ค๋ฉด, ์ด์ ๋ border์ ์ ์ฉํด๋ณผ ์ฐจ๋ก์ด๋ค.
border-image,border-image-slice๋ฅผ ์ด์ฉํด์ ๊ทธ๋ผ๋ฐ์ด์
์ ๋ง๋๋ฉด ๊ณ ์ฅ์ด๋๋ค.
๊ทธ๋ผ๋ฐ์ด์ ์ค์ฒฉ ์ ์ฉ์ด ์๋ ๋ฟ๋๋ฌ, border-radius๋ฅผ ์ ์ฉํด๋ ๋ค๋ชจ ๋ชจ์์ด๋ค.
.border {
border-radius: 3.3rem;
border: 10px solid;
border-image: linear-gradient(to bottom right, rgba(104, 121, 251, 0.6), rgba(104, 121, 251, 0));
border-image-slice: 1;
}
.border {
border: 10px solid;
border-image: linear-gradient(to bottom right, rgba(104, 121, 251, 0.6), rgba(104, 121, 251, 0))
radial-gradient(farthest-corner at 0% 100%, rgba(255, 255, 255, 0) 0%, rgba(104, 121, 251, 0.25) 100%)
radial-gradient(farthest-corner at 0% 100%, rgba(255, 255, 255, 0) 0%, rgba(104, 121, 251, 0.25) 100%);
border-image-slice: 1;
}

์๊ณ ๋ณด๋ border-imageย ์์ฑ๊ณผย border-radiusย ์์ฑ์ดย ํธํ์ด ๋์ง ์๋๋ค๊ณ ํ๋ค.
2๋ฒ์งธ ๋ฐฉ๋ฒ์ด๋ค. background-image์ ์ ์ฉํ๊ณ , background-clip์์ฑ์ ์ด์ฉํ์ฌ border์์ญ๊ณผ content์์ญ์ ๋๋์ด์ฃผ๋ ๊ฒ์ด๋ค.
.box {
border: 10px dashed red;
padding: 10px;
background-image: linear-gradient(to bottom right, rgba(104, 121, 251, 0.6), rgba(104, 121, 251, 0.6));
background-clip: content-box; /* default */
}

background-clip์ ์ด์ฉํ์ฌ ์ํ๋ ์์ญ์๋ง background-image๋ฅผ ์ ์ฉํ ์ ์๋ค.
๊ฐ ์์ญ์ ๊ฐ๋ฐ์๋๊ตฌ๋ฅผ ์ด์ฉํ๋ฉด ๋ ์ฝ๊ฒ ํ์ธํ ์ ์๋ค.
์ด ๊ธฐ๋ฒ์ ์ด์ฉํด์ border-box์๋ border์ ์ ์ฉ๋๊ธฐ ์ํ๋ ๊ทธ๋ผ๋ฐ์ด์ 3๊ฐ๋ฅผ ์ ์ฉํ๊ณ , content-box์๋ง ๋ฐฐ๊ฒฝ์ ์ ์ฉ๋ ๊ทธ๋ผ๋ฐ์ด์ 1๊ฐ๋ฅผ ๊ฐ๋ฐํ๋ฉด ๋๊ฒ ๋ค! ๋ ๋ด ์์ผํ ์๊ฐ์ด์๋ค.
.box {
border: 20px solid transparent;
border-radius: 3.5rem;
background-image: radial-gradient(farthest-corner at 0 0, rgba(104, 121, 251, 0.4) 0%, rgba(255, 255, 255, 0) 80%),
linear-gradient(to bottom right, rgba(104, 121, 251, 0.6), rgba(104, 121, 251, 0)),
radial-gradient(farthest-corner at 0% 100%, rgba(255, 255, 255, 0) 0%, rgba(104, 121, 251, 0.25) 100%),
linear-gradient(to bottom right, rgba(255, 255, 255, 0.5), rgba(104, 121, 251, 0.3), rgba(255, 255, 255, 0.5));
background-origin: border-box;
background-clip: content-box, border-box, border-box, border-box;
}

์ ์์ด๋ ์ฃ ?? ์๊น์ด ๋๋ฌด ์งํ๋ค.!!
๊ทธ๋๋ ๋คํ์ค๋ฌ์ด ์ ์ border-radius๊ฐ ์ ์ฉ๋๋ค๋ ๊ฒ๊ณผ, border์ ๊ทธ๋ผ๋ฐ์ด์ 3๊ฐ๊ฐ ์ค์ฒฉ๋๋ค๋ ๊ฒ์ด๋ค.. ๐
content์์ญ์ ์์์ด ํฌ๋ช ๋๊ฐ ์๋ค๋ณด๋ ์๋์ชฝ border ์์ญ๊น์ง ์ค์ฒฉ๋์ด์ content์์ญ์๋ ์ง๊ธ 4๊ฐ์ ๊ทธ๋ผ๋ฐ์ด์ ์ด ๋ชจ๋ ๋ค์ด๊ฐ๊ฒ ๋ ๊ฒ์ด์๋ค.
ํด๊ฒฐ์ฑ ์ผ๋ก, content์์ญ์ ํฐ์์ผ๋ก ๋ฎ์ด์ฃผ๊ณ , ์์ ๋ฐ๋ก ๊ทธ๋ผ๋ฐ์ด์ content๋ฅผ ๋ง๋ค์ด ์ฃผ๋ ๊ฒ์ด๋ค.
.Border {
border: 3px solid transparent;
border-radius: 3.5rem;
background-image: linear-gradient(#fff, #fff),
linear-gradient(to bottom right, rgba(104, 121, 251, 0.6), rgba(104, 121, 251, 0)),
radial-gradient(farthest-corner at 0% 100%, rgba(255, 255, 255, 0) 0%, rgba(104, 121, 251, 0.25) 100%),
linear-gradient(to bottom right, rgba(255, 255, 255, 0.5), rgba(104, 121, 251, 0.3), rgba(255, 255, 255, 0.5));
background-origin: border-box;
background-clip: content-box, border-box, border-box, border-box;
}
.Background {
width: 100%;
height: 100%;
border-radius: 3.3rem;
background-image: radial-gradient(farthest-corner at 0 0, rgba(104, 121, 251, 0.4) 0%, rgba(255, 255, 255, 0) 80%);
}

์!! ์์ฑ! ์ธ์ค ์์๋๋ฐ!!! ํ๋ฉด์ ๋ฃ์ผ๋ ค๊ณ ๋ณด๋ ์์ง์ด๋คโฆโฆ
์ฌ๊ธฐ์ ๋ฉ์ถ๋ฉด, ๋ฐฐ๊ฒฝ์ด ํฐ์์ด ์๋ ๋๋ ์ธ ์๊ฐ ์๋คโฆ!! ๐คฃ ๐ฅ๐ฅ๐ฅ
์ฌ๊ธฐ์๋ถํฐ๋ ๋ญ๋ผ๊ณ ๊ฒ์ํด์ผ ํ ์ง๋ ๋ชจ๋ฅด๊ฒ ์๋ค. ์์นญ์ ์ด์ฌํ ํ๋ค๊ฐ ๊ด๋ จํด์ ๋ธ๋ก๊ทธ์ ์ฝ๋๋ฅผ ์ฌ๋ ค๋์ ๋ถ์ด ๋ฑ ํ ๋ถ ๊ณ์ จ๋ค..! ์ง์ง ์ด ๋ถ ์๋์์ผ๋ฉด,,, ํฌ๊ธฐํ ๋ป ํ๋ค..ใ ใ (๋ฌดํํ ๊ฐ์ฌ ์ธ์ฌ๋ฅผ..)
mask ๋ฅผ ํ์ฉํ๋ ๋ฐฉ๋ฒ์ด๋ค.
์์ ์ฝ๋์์๋ content-box์ ํฐ์์ ์ ์ฉํ๊ณ , ํฐ์์ -webkit-mask-composite ๊ณผ mask-composite ์์ฑ์ ์ด์ฉํด์ ์ค๋ณต๋๋ ๋ถ๋ถ์ ์์ ํฌ๋ช
ํ๊ฒ ๋ง๋๋ ๊ฒ์ด๋ค.
-webkit-mask-composite ๊ณผ mask-composite ๋ ๊ฐ์ ์ญํ ์ ํ๋๋ฐ, -webkit-mask-composite ๋ Chrome, Safari๋ธ๋ผ์ฐ์ ์์ ์ง์ํ๊ณ , mask-composite ๋ Firefox์์ ์ง์ํ๋ค. ๋ฐ๋ผ์ ๊ฐ์ด ์ฌ์ฉํด์ค๋ค.
์ค์ ๋ก -webkit-mask-composite ๊ณต์๋ฌธ์๋ฅผ ํ์ธํ๋ฉด, Non-standard ๋นจ๊ฐ๋ฑ์ง๊ฐ ๋ถ์ด์๋ ๊ฒ์ ๋ณผ ์ ์๋ค. ๋ชจ๋ ์ฌ์ฉ์์๊ฒ ์ ์ฉ๋์ง ์์ ์ ์์ผ๋ ์กฐ์ฌํด์ผ ๋๋ค๋ ๊ฒ์ด๋ค.
.Border{
position: relative;
box-sizing: border-box;
background-clip: padding-box;
&:before {
content: '';
position: absolute;
inset: 0;
border-radius: 3.5rem;
backdrop-filter: blur(21px);
padding: 3px;
background: linear-gradient(to bottom right, rgba(104, 121, 251, 0.6), rgba(104, 121, 251, 0)),
radial-gradient(farthest-corner at 0% 100%, rgba(255, 255, 255, 0) 0%, rgba(104, 121, 251, 0.25) 100%),
linear-gradient(to bottom right, rgba(255, 255, 255, 0.5), rgba(104, 121, 251, 0.3), rgba(255, 255, 255, 0.5));
-webkit-mask:
linear-gradient(#fff 0 0) content-box,
linear-gradient(#fff 0 0);
-webkit-mask-composite: xor;
mask-composite: exclude;
}
}

::before ๋ ์์ ์์ ๊ฐ์ ์์๋ฅผ ๋ง๋ค์ด์ฃผ๋๋ฐ, ์ฃผ๋ก ๊ธฐํธ๋ ๋ํ ๋ฑ ๊พธ๋ฏธ๊ธฐ ์ํด์ ์ฌ์ฉํ๋ค๊ณ ํ๋ค.
๋๋ ๋ฐฐ์น๊ฐ ๋ ์ด๋ ค์ด ๊ฒ ๊ฐ์์ ์ฐ์ ::before ๋นผ๊ณ ๋ง๋ค์ด ์ฃผ๊ฒ ๋ค. ๋ฐฐ๊ฒฝ์๊น์ง ๋ฃ์ด์ฃผ๊ฒ ๋ค.
๊ทธ๋ฆฌ๊ณ ์ฝ๋๋ฅผ ๋ณด๋ฉด, ์ด๋๊น์ง์๋ ๋ค๋ฅด๊ฒ border-content ๋ฐ์ค๋ฅผ ์ด์ฉํ๊ฒ์ด ์๋, padding-content๋ก ๊ตฌ๋ถ์ง๋ ๊ฒ์ด ๋ณด์ธ๋ค. border๋ก ํ๋ ๊ทธ๋ผ๋ฐ์ด์ ํ ๋๋ฆฌ๊ฐ ๋ค ๋์ค์ง ์๋ ๋ฌธ์ ๊ฐ ์์๋ค. ๊ทธ๋์ padding์ผ๋ก ์ฌ์ฉํ๋ค.
.Box {
border-radius: 3.5rem;
box-sizing: border-box;
background-clip: padding-box;
padding: 3px;
background: linear-gradient(to bottom right, rgba(104, 121, 251, 0.6), rgba(104, 121, 251, 0)),
radial-gradient(farthest-corner at 0% 100%, rgba(255, 255, 255, 0) 0%, rgba(104, 121, 251, 0.25) 100%),
linear-gradient(to bottom right, rgba(255, 255, 255, 0.5), rgba(104, 121, 251, 0.3), rgba(255, 255, 255, 0.5));
-webkit-mask:
linear-gradient(#fff 0 0) content-box,
linear-gradient(#fff 0 0),
radial-gradient(farthest-corner at 0 0, rgba(104, 121, 251, 0.4) 0%, rgba(255, 255, 255, 0) 80%);
-webkit-mask-composite: xor;
mask-composite: exclude
}

์ด์ ์ง์ง ๋ง์ง๋ง์ผ๋ก ์ฌ๊ธฐ์ blur์ฒ๋ฆฌ๊น์ง ํด์ฃผ๊ฒ ๋ค.
์์ ์ฝ๋์์ ๊ทธ๋ฅ ์๋ ํ ์ค์ ์ถ๊ฐํ๋ฉด ์ ๋ง ์ฐํด์ง๊ณ ๋ท ๋ฐฐ๊ฒฝ์ด ๋ธ๋ฌ์ฒ๋ฆฌ๊ฐ ๋์ง๋ ์์๋ค.
backdrop-filter: blur(5px);
๋ธ๋ฌ๋ถ๋ถ์ ๋ฐ๋ก ๋นผ๋ฉด ๋ธ๋ฌ๊ฐ ๋์ค๋๋ฐ, border-radius๊ฐ ์ ์ฉ๋์ง ์์๋ค. ๊ทธ๋์ ์๋จ์์ overflow: hidden์ ์ฃผ์๋ค.
์ต์ข ์ ์ผ๋ก ์์ฑ๋ ์ฝ๋๋!
์๋ React, Styled-component์ธ๋ฐ ํด๋น ๋ถ๋ถ๋ง ๋บ๋ค.
//html
<Front>
<Blur />
<Border />
</Front>
//css
.Front {
position: absolute;
width: 100%;
height: 100%;
border-radius: 3.5rem;
overflow: hidden;
transform: rotate(-0.157deg);
}
.Border {
width: 100%;
height: 100%;
position: absolute;
border-radius: 3.5rem;
box-sizing: border-box;
background-clip: padding-box;
padding: 3px;
background-image: linear-gradient(to bottom right, rgba(104, 121, 251, 0.6), rgba(104, 121, 251, 0)),
radial-gradient(farthest-corner at 0% 100%, rgba(255, 255, 255, 0) 0%, rgba(104, 121, 251, 0.25) 100%),
linear-gradient(to bottom right, rgba(255, 255, 255, 0.5), rgba(104, 121, 251, 0.3), rgba(255, 255, 255, 0.5));
-webkit-mask:
linear-gradient(#fff 0 0) content-box,
linear-gradient(#fff 0 0),
radial-gradient(farthest-corner at 0 0, rgba(104, 121, 251, 0.4) 0%, rgba(255, 255, 255, 0) 80%);
-webkit-mask-composite: xor;
mask-composite: exclude;
}
.Blur {
position: absolute;
width: 100%;
height: 100%;
background-color: rgba(255, 255, 255, 0);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(5px);
}

์์ฑ์ด๋ค! ๐
๊ทผ๋ฐ ์ฌ๊ธฐ์ ์ด์ ์ปดํฌ๋ํธ state๋ณ ์์ ๋ณํ๋โฆ. ์ด๊ฒ์ ๊ฒ ๋จ์๋ค..
์ฐธ๊ณ ์๋ฃ
https://developer.mozilla.org/ko/docs/Web/CSS/CSS_images/Using_CSS_gradients
https://codingeverybody.kr/css-background-clip-์์ฑ/
https://cheesechaos.tistory.com/45
https://developer.mozilla.org/en-US/docs/Web/CSS/-webkit-mask-composite
ํ์๋ค์ด ์ฌ์ธํจ์ด ๋๊ปด์ง๋ ๊ธ์ด๋ค์!!
์ ๋ณด๊ณ ๊ฐ๋๋ค :)