Why does BEM often use two underscores instead of one for modifiers?

前端 未结 5 1879
梦如初夏
梦如初夏 2021-01-31 18:26

In BEM, I understand that with modifiers, two dashes makes sense so that you can distinguish the modifier in my-block-my-modifier with my-block--my-modifier

5条回答
  •  终归单人心
    2021-01-31 19:16

    It's also worth mentioning that the BEM syntax is not forced upon us and if you find another syntax that you find more readable then by all means go with that. The important thing is consistency, ensuring other developers work to the same syntax.

    An example of an alternative syntax used is in SUIT CSS by Nicolas Gallagher. Which uses the following syntax.

    ComponentName
    ComponentName--modifierName
    ComponentName-elementName
    ComponentName.is-stateOfComponent
    

    You can read more here SUIT CSS naming conventions

提交回复
热议问题