티스토리 뷰

CSS

[CSS] Specificity

Dongi 2021. 12. 21. 14:32

안녕하세요 동기 여러분! 오늘은 type vs class vs ID에 대해 싸움을 붙여봅시다!

 

Specificity

type과 class, id 모두 같이 적용한다면 무엇이 적용될까요?

 


 

ROUND 1

type vs class vs id

 

<h1 class='blueclass' id='greenclass'>승자는 누구인가!</h1>

type이 승리시 빨간 글씨

class가 승리시 파란 글씨

id가 승리시 초록 글씨가 나오게 설정해두었습니다.

h1 {
  color: red;
}

.blueclass {
  color: blue;
}

#greenclass {
  color: green;
}

 

결과는?

초록 글씨 id 승리!

 

id의 승리!!!

 


 

ROUND 2

type vs class

 

<h1 class='blueclass'>승자는 누구인가!</h1>

 

type이 승리시 빨간 글씨

class가 승리시 파란 글씨가 나오게 설정해두었습니다.

h1 {
  color: red;
}

.blueclass {
  color: blue;
}

 

결과는?

파란 글씨 class 승리!

class의 승리!!!

 


 

결과

id > class > type 

id가 가장 먼저 적용되고 그다음 class 그다음은 type입니다.

 


 

오늘의 느낌

아 저녁은 짜파게티를 먹었습니다. 미안 참깨라면ㅋㅋ

'CSS' 카테고리의 다른 글

[CSS] Descendant Combinator  (0) 2021.12.22
[CSS] Chaining  (0) 2021.12.22
[CSS] Pseudo-class  (0) 2021.12.21
[CSS] Attribute  (0) 2021.12.20
[CSS] ID  (0) 2021.12.19
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
글 보관함