๐Ÿ”ฅ css ๋ถ€๋ชจ ์„ ํƒ์ž๋Š” ๋ฌด์—‡์ž…๋‹ˆ๊นŒ?

2576 ๋‹จ์–ด htmlcsswebdev
:has๋Š” ๋ถ€๋ชจ ์„ ํƒ์ž ์˜์‚ฌ ํด๋ž˜์Šค*์ž…๋‹ˆ๋‹ค. ํŠน์ • ํ•˜์œ„ ๋˜๋Š” ๋’ค์— ์˜ค๋Š” ํŠน์ • ์š”์†Œ๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ( :has ) ์ƒ์œ„ ์š”์†Œ ์†์„ฑ์„ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

A CSS pseudo-class is a keyword added to a selector that specifies a special state of the selected element(s). For example, :hover can be used to change a button's color when the user's pointer hovers over it.



๋‹ค์Œ์€ :has ์˜์‚ฌ ํด๋ž˜์Šค์˜ ๊ฐ„๋‹จํ•œ ์˜ˆ์ž…๋‹ˆ๋‹ค.

.parent:has(.child){
  color: blue;
}

์ด๊ฒƒ์ด ์˜๋ฏธํ•˜๋Š” ๋ฐ”๋Š” .parent ์š”์†Œ์— .child ์š”์†Œ๊ฐ€ ํฌํ•จ๋œ ๊ฒฝ์šฐ ์ƒ์œ„ ์š”์†Œ์˜ ํ…์ŠคํŠธ ์ƒ‰์ƒ์„ ํŒŒ๋ž€์ƒ‰์œผ๋กœ ๋ณ€๊ฒฝํ•œ๋‹ค๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์ด์ „์—๋Š” css๋กœ ๊ตฌํ˜„ํ•  ์ˆ˜ ์—†์—ˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ :has ์„ ํƒ๊ธฐ ๋•๋ถ„์— ์ด์ œ ์ด ๋…ผ๋ฆฌ๋ฅผ css์— ์ง์ ‘ ์ถ”๊ฐ€ํ•˜๊ณ  ํ•˜์œ„ ํ•ญ๋ชฉ.parent์— ๋”ฐ๋ผ ์ˆ˜์ •:hasํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

At the time of writing this article :has pseudo-class only works in Safari 15.4 and in Chrome Canary. Can i use


์˜ˆ์‹œ



ํ˜ธํ™˜๋˜๋Š” ๋ธŒ๋ผ์šฐ์ €์—์„œ ์ฝ”๋“œํŽœ์„ ์—ด์ง€ ์•Š์•„๋„ ๋˜๋„๋ก ์—ฌ๊ธฐ์„œ ์Šคํฌ๋ฆฐ์ƒท์„ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ;)

๋นˆ ๋ฒ„ํŠผ๊ณผ SVG๊ฐ€ ์žˆ๋Š” ๋ฒ„ํŠผ





์•„์ด์ฝ˜์ด ์žˆ๊ฑฐ๋‚˜ ์—†๋Š” 2๊ฐ€์ง€ ๋ณ€ํ˜• ๋ฒ„ํŠผ์„ ์‚ฌ์šฉํ•˜๋Š” ๋Œ€์‹  ๋ถ€๋ชจ์—์„œ :has ์†์„ฑ์„ ๊ฐ„๋‹จํžˆ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

button:has(svg) {
  background: #bd3c91;
}
:has ์„ ํƒ์ž์— ๋” ๋งŽ์€ ๊ฒƒ์ด ์žˆ์Šต๋‹ˆ๋‹ค. ๋” ๋งŽ์€ ์‚ฌ์šฉ ์‚ฌ๋ก€์— ๊ด€์‹ฌ์ด ์žˆ๋Š” ๊ฒฝ์šฐ ์˜๊ฒฌ์— ์•Œ๋ ค์ฃผ์‹œ๋ฉด ๋” ์‹ค์šฉ์ ์ธ ์‚ฌ์šฉ ์‚ฌ๋ก€๋ฅผ ์ถ”๊ฐ€ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.



์•„์Šฌ๋žŒ ์ƒค ํŒ”๋กœ์šฐ



Currently working on https://codedmails.com

์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ