Skip to content

๐Ÿฃ ๋ถ€๋ชจ ์š”์†Œ์˜ ์ƒํƒœ์— ๋”ฐ๋ผ ์ž์‹ ์š”์†Œ๋„ ์Šคํƒ€์ผ ๋ณ€ํ™” ๋ถ€์—ฌํ•˜๊ธฐ

baegyeong edited this page Nov 12, 2024 · 1 revision

์šฐ๋ฆฌ ์„œ๋น„์Šค์—์„œ๋Š” ์‚ฌ์ด๋“œ๋ฐ”๊ฐ€ ์žˆ๊ณ , ๊ฐ๊ฐ์˜ li์— hover๋ฅผ ํ•˜๋ฉด ์ƒ‰์ƒ์ด ๋ณ€๊ฒฝ๋˜์–ด์•ผ ํ•œ๋‹ค.

์•„๋ž˜ ์‚ฌ์ง„์€ ์‚ฌ์ด๋“œ๋ฐ”์˜ ์ผ๋ถ€๋‹ค.

์—ฌ๊ธฐ์„œ li๊ฐ€ hover ๋  ๋•Œ ์–ด๋–ป๊ฒŒ button๊ณผ p ํƒœ๊ทธ์˜ ์ƒ‰์ƒ์„ ๋ฐ”๊ฟ€ ์ˆ˜ ์žˆ์„๊นŒ?


์ฒ˜์Œ์— ์ƒ๊ฐํ•œ ๊ฒƒ์€,

 <li className="hover:[&_>]:text-orange hover:[&_>]:fill-orange ... >

์ด๋Ÿฐ ์‹์œผ๋กœ li์— hover๊ฐ€ ๋์„ ๋•Œ, ์ง๊ณ„ ์ž์†์„ ์„ ํƒํ•ด์„œ ์ƒ‰์ƒ์„ ๋ฐ”๊ฟ”์ฃผ๋ ค๊ณ  ํ–ˆ๋‹ค.

ํ•˜์ง€๋งŒ ๊ฐ๊ฐ hover๊ฐ€ ๋๊ณ  ๋™์‹œ์— ๋˜์ง„ ์•Š์•˜๋‹ค.

useState๋กœ ์ƒํƒœ๋ฅผ ๋ถ€์—ฌํ•˜๋Š” ๊ฒƒ์€ ๋„ˆ๋ฌด ๊ณผํ•˜๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ๋‹ค.


์ฐพ์•„๋ณด๋‹ˆ tailwind์—์„œ๋Š” ๋ถ€๋ชจ ์ƒํƒœ์— ๊ธฐ๋ฐ˜ํ•˜์—ฌ ์Šคํƒ€์ผ์„ ํ•  ์ˆ˜ ์žˆ๋Š” group ์„ ํƒ์ž๊ฐ€ ์žˆ์—ˆ๋‹ค! (๋น„์Šทํ•˜๊ฒŒ ํ˜•์ œ์— ๊ธฐ๋ฐ˜ํ•œ peer๋„ ์žˆ๋‹ค.)

์‚ฌ์šฉ๋ฒ•์€ ๊ฐ„๋‹จํ•˜๊ฒŒ ๋ถ€๋ชจ์— group className์„ ๋ช…์‹œํ•˜๊ณ , hover, active, focus ์ƒํƒœ์ผ ๋•Œ ์ž์‹์—์„ธ ์Šคํƒ€์ผ์„ ๋ถ€์—ฌํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด group-hover, group-active, group-focus ์™€ ๊ฐ™์ด ๊ธฐ์ž…ํ•˜๋ฉด ๋œ๋‹ค.

  <li className="group flex items-center gap-10">
    <button
      type="button"
      className="fill-gray group-hover:fill-orange transition-colors"
    >
      {icon}
    </button>
    <p
      className={cn(
        'text-gray display-medium16 whitespace-nowrap',
        'group-hover:text-orange transition-all group-hover:font-bold',
        isHovered ? 'display' : 'hidden',
      )}
    >
      {text}
    </p>
  </li>
  • ๋ถ€๋ชจ์ธ li ํƒœ๊ทธ์— group์„ ๋ถ€์—ฌ
  • ์ž์‹์ธ button๊ณผ p ํƒœ๊ทธ์— group-hover ์ถ”๊ฐ€

๐Ÿœ ํŒ€ ๊ฐœ๋ฏธ

๐Ÿ›๏ธ ํŒ€ ๋ฌธํ™”

๊ฐœ๋ฐœ ์œ„ํ‚ค

FE

BE

Infra

๐Ÿ—ฃ๏ธ ๋ฐœํ‘œ

๐Ÿ“š ํšŒ์˜๋ก

๐Ÿ”ด ์ธํ„ฐ๋ฏธ์…˜
๐ŸŸ  1์ฃผ์ฐจ
๐ŸŸก 2์ฃผ์ฐจ
๐ŸŸข 3์ฃผ์ฐจ
๐Ÿ”ต 4์ฃผ์ฐจ
๐ŸŸฃ 5์ฃผ์ฐจ
๐ŸŸค 6์ฃผ์ฐจ

๐Ÿ’ญ ํšŒ๊ณ 

๐Ÿง‘โ€๐Ÿคโ€๐Ÿง‘ ๋ฉ˜ํ† ๋ง

Clone this wiki locally