[css] How CSS Works? and what is Specificity?

2018. 7. 12. 17:18・Frontend/HTML, CSS

This is so extremely important because getting started with CSS is actually very easy but really knowing what's going on behind scenes is completely different, and it's really not as easy as getting started.

 

 

 

 


 

[Specificity]

1. inline styles

2. IDs

3. classes, pseudo-classes, attribute

4. Elements, pseudo-elements

(Inline, IDs, Classes, Elements)

 

  • CSS declarations marked with !important have the highest priority.
  • but only use !important is as a last resource. It's better to use correct Specificites - maintainable code!
  • Inline styles will always have the priority over style in external stylesheets.
  • A selector that contains 1 IDs is more specific than one with 1000 classes.
  • A selector that contains 1 classes is more specific than one with 1000 Elements.
  • The universal selector * has no specificity value (0,0,0,0) which means that all other selectors have a precedence over it.
  • Rely more on specificity than on the order of selectors.
  • But rely on order when using 3rd-party stylesheets - always put your stylesheet last.
저작자표시 비영리 (새창열림)

'Frontend > HTML, CSS' 카테고리의 다른 글

[Sass] Architect : the 7 - 1 pattern  (0) 2018.07.20
[css] the problem of setting the font-size to pixels of body element  (0) 2018.07.15
[css] Inheritance In CSS  (0) 2018.07.13
[css] How UNITS are converted from relative to absolute(px)  (0) 2018.07.13
px, %, rem, em 변환과정  (0) 2017.12.27
'Frontend/HTML, CSS' 카테고리의 다른 글
  • [css] the problem of setting the font-size to pixels of body element
  • [css] Inheritance In CSS
  • [css] How UNITS are converted from relative to absolute(px)
  • px, %, rem, em 변환과정
dev.hyejin
dev.hyejin
  • dev.hyejin
    혜진의 개발자 성장블로그
    dev.hyejin
  • 전체
    오늘
    어제
    • 분류 전체보기 (89)
      • 2024 데브캠프 (2)
      • 회고 (1)
      • 이슈해결 (3)
      • 기초학습 (13)
      • Frontend (20)
        • JavaScript (3)
        • Git, GitHub (3)
        • HTML, CSS (14)
      • Backend (8)
        • Database (4)
        • Java (4)
      • CS (16)
        • Network (10)
        • Algorithm (6)
      • Eng (16)
      • Tips (5)
  • 인기 글

  • 태그

    border-box
    상대경로
    시간복잡도
    점근성능
    box-sizing
    ER모델
    런타임
    객체
    절대경로
    GitHub
  • hELLO· Designed By정상우.v4.10.3
dev.hyejin
[css] How CSS Works? and what is Specificity?
상단으로

티스토리툴바