๐Ÿ“œ ์Šคํฌ๋กค๋ฐ” CSS ์ ์šฉํ•˜๊ธฐ ( feat. ::-webkit-scrollbar, ํ”„๋ก ํŠธ์•ค๋“œ )

2021. 8. 31. 13:55ใ†CSS

๊ฒฐ ๋ก 

::-webkit-scrollbar {

  height0px;

  width5px;

}

::-webkit-scrollbar-thumb {

  background-colorrgb(170165165);

  border-radius30px;

}

 

 

๐Ÿ‘€ Safari / Chrome ํ™˜๊ฒฝ์—์„œ ๋™์ž‘ํ•˜๋Š” ์Šคํฌ๋กค์€ ::-webkit-scrollbar ์„ ์ด์šฉํ•ด CSS ์กฐ์ ˆ์ด ๊ฐ€๋Šฅํ•˜๋‹ค.
์‚ฌ์ง„์€ CSS๋ฅผ ์ ์šฉํ•˜์ง€ ์•Š์€ ๊ธฐ๋ณธ ์Šคํฌ๋กค๋ฐ” ํ™”๋ฉด์œผ๋กœ, ๊ฐ„๋‹จํ•œ css ์ ์šฉ์„ ํ†ตํ•ด ๋‚ ์”ฌ์ด๋กœ ๊ฑฐ๋“ญ๋‚  ์ˆ˜ ์žˆ๋‹ค.

 

 

๋‚  ๊ฒƒ ๊ทธ๋Œ€๋กœ์˜ ์Šคํฌ๋กค ๋ฐ” ( It's raw )

 

Result

See the Pen by wkddkdud (@angpeng) on CodePen.

 



1. ::-webkit-scrollbar _ ์Šคํฌ๋กค๋ฐ” ์ „์ฒด ์˜์—ญ ์กฐ์ ˆ

::-webkit-scrollbar {
  height: 0px; /*  x์ถ• ์Šคํฌ๋กค  */
  width: 5px;  /*  y์ถ• ์Šคํฌ๋กค  */
  box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.2);
}

height์„ ํ†ตํ•ด x์ถ•์˜ ๊ฐ€๋กœ ์Šคํฌ๋กค & width๋ฅผ ํ†ตํ•ด y์ถ•์˜ ์„ธ๋กœ ์Šคํฌ๋กค์„ ์กฐ์ ˆํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ,

height์„ 0์œผ๋กœ ์ง€์ •ํ•  ๊ฒฝ์šฐ x์ถ•์— overflow๊ฐ€ ๋ฐœ์ƒํ•ด๋„ ์Šคํฌ๋กค ๋ณด์ด์ง€ ์•Š์•„ ๊น”๋”ํ•œ ํ™”๋ฉด์ด ๊ฐ€๋Šฅํ•˜๋‹ค. (๋„Œ ๋งˆ์น˜ ์นด๋ฉœ๋ ˆ์˜จ)

backgound ๋‚˜ box-shawdow์„ ์ž‘์„ฑํ•  ๊ฒฝ์šฐ ์Šคํฌ๋กค์— ์ƒ‰์ƒ์ด ์ ์šฉ๋œ๋‹ค. ์ž‘์„ฑํ•˜์ง€ ์•Š์„ ๊ฒฝ์šฐ ๊ธฐ๋ณธ ๋ฐฐ๊ฒฝ์ƒ‰์€ ํฐ์ƒ‰์ด๋‹ค.

 

 

2. ::-webkit-scrollbar-thumb _ ์Šคํฌ๋กค ์ƒ์„ฑ๋˜๋Š” ์˜์—ญ

::-webkit-scrollbar {  // ์Šคํฌ๋กค๋ฐ” ์ž์ฒด ์˜์—ญ
  height: 0px;
  width: 5px;
}

::-webkit-scrollbar-thumb { /* ์Šคํฌ๋กค ์˜์—ญ */
  background-color: rgb(170, 165, 165);  /* ์Šคํฌ๋กค ์˜์–ต ์ƒ‰์ƒ ์กฐ์ ˆ */
  border-radius: 30px;  /*  ์Šคํฌ๋กค ๋ง๋‹จ radius ์กฐ์ ˆ  */
}

์Šคํฌ๋กค ์˜์—ญ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๊ฒŒ ์Šคํฌ๋กค ์˜์—ญ์— ์ƒ‰์ƒ( background-color )์„ ์ ์šฉํ•˜๊ณ ,
๋”ฑ๋”ฑํ•ด ๋ณด์ด์ง€ ์•Š๊ฒŒ ์Šคํฌ๋กค ๋ง๋‹จ์˜ border์˜ ๊ฐ๋„๋ฅผ ์กฐ์ ˆํ•ด ๋‘ฅ๊ธ€๋‘ฅ๊ธ€ํ•œ ๋Š๋‚Œ์„ ๋”ํ•ด์ค€๋‹ค.

 

css ์ ์šฉ๋œ ์Šคํฌ๋กค

์ด ์™ธ์—๋„ ๋‹ค์–‘ํ•œ css ์†์„ฑ์ด ์กด์žฌํ•œ๋‹ค.

3. ::-webkit-scrollbar-track _ ์Šคํฌ๋กค ์˜์—ญ ์ œ์™ธ ๋ถ€๋ถ„

::-webkit-scrollbar {
  height: 0px;
  width: 5px;
  background-color:red;
}

::-webkit-scrollbar-thumb {
  background-color: rgb(170, 165, 165);
  border-radius: 30px;
}

::-webkit-scrollbar-track{
  background-color:blue
}

4. ::-webkit-scrollbar-button: start:decrement & end:increment _ ์Šคํฌ๋กค ์ƒํ•˜ ์ด๋™ ๋ฒ„ํŠผ ์˜์—ญ

::-webkit-scrollbar-button:start:decrement, 
::-webkit-scrollbar-button:end:increment {
  height:40px;
  background-color: white;
}

ํฐ์ƒ‰ ์˜์—ญ์˜ ์ƒํ•˜ ์กฐ์ ˆ ๋ฒ„ํŠผ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

5. ::-webkit-scrollbar-corner  _ x์ถ• & y์ถ• ์Šคํฌ๋กค ์ ‘์  ๋ถ€๋ถ„

::-webkit-scrollbar-corner {
      background-color: yellow;
}

Posted by Ang