Coding/CSS

class / id 선택자 우선순위 (헷갈려 !!)

민톨이 2024. 1. 2. 00:04
728x90

-한 속성에 대해 여러개의 class가 있다면 우선적으로 적용되는 것은 나중에 오는 것이다

 ex) <h1 class="a-class another-class"> Hello </h1>

 

.a-class {

  color: green;

}

 

.another-class {

  color: blue;

}

 

=> 이 경우에 우선적으로 적용되는 것은? 더 나중에 적힌 코드인 another-class이다. blue 적용 !

 

-id가 class보다 우선적용

ex) <h1  class="a-class" id="an-id">Hello</h1>

 

.a-class {

  color: blue;

}

 

#an-id {

color: green;
}

 

=> 이 경우에 우선적으로 적용되는 것은? id 선택자인 후자의 것이다. green 적용!

 

 

 

 

 

 

 

'Coding > CSS' 카테고리의 다른 글

flexbox(플렉스박스)  (1) 2024.01.04
크롬 개발자도구로 웹폰트 적용하기  (1) 2024.01.04
ol / li 색 부여  (0) 2024.01.01
CSS 기본 속성(padding/margin)  (0) 2024.01.01
Color/Font Properties  (0) 2023.12.31