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

前端 未结 5 1869
梦如初夏
梦如初夏 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 18:52

    Double Underscore is used to define sub element of a block.

    i.e:

    
    

    Where main-nav is a block & main-nav__item is a sub element.

    This is done because some people might name their block like this main_nav which will create confusion with single underscore like this : main_nav_item

    Therefore double underscore will clarify stuff like this: main_nav__item.

提交回复
热议问题