front end

CSS에 hyphen(-)을 사용해야 하는 이유

노루아부지 2022. 10. 17. 23:00
  1. CSS는 이미 hyphen을 사용하고 있습니다.
    1. margin-left, padding-top, font-size 등 이미 CSS는 hyphen으로 되어있습니다.
    2. jQuery 또한 모두 hyphen으로 되어있습니다.
  2. 가독성이 더 좋습니다.
    1. navHome -> nav-home
    2. marginLeft -> margin-left
    3. paddingTop -> padding-top
  3. hyphen을 사용하면 CSS에서 제공하는 selector를 사용할 수 있습니다.
    1. CSS2 파이프 패턴: [class|="col"]
      다른 selector는 여기
    2. CSS3 star 패턴: [css*="col-"]
      다른 selector는 여기

 

 

 

reference

http://jasonbuckboyer.com/playground/use-hyphens-in-css/

 

Use Hyphens in Your CSS Naming Conventions

CSS is already a hyphen-happy syntax margin-left, padding-top, font-size, etc. We already write CSS with hyphens. It's natural and consistent to use hyphens for our CSS declarations and our HTML class names and IDs. It is inconsistent to make our class nam

jasonbuckboyer.com

 

728x90
loading