给定以下 BEM 树结构,其中存在五个嵌套级别:
collection-main__features-top__story__byline__author
根据 BEM 的命名约定,元素是块的一部分并且在它所属的块之外没有任何意义,那么命名author
类的正确方法是什么?
由于 anauthor
在语义上与byline
andstory
上下文相关,但在features-top
andcollection-main
块下没有意义,那么最好的 BEM 名称是什么?
collection-main__author
features-top__author
story__author (best?)
story__byline__author
byline__author
如果features
引入了新区块会发生什么?
collection-main__features-top__story__byline__author (target)
collection-main__features-bottom__story__byline__author
features-top__story__author
story--features-top__author (best?)
最后,如果collection
添加了另一个块并且我们想要为列表中的第二个作者元素设置样式会发生什么?
collection-main__features-top__story__byline__author
collection-main__features-bottom__story__byline__author (target)
collection-sub__features-top__story__byline__author
collection-sub__features-bottom__story__byline__author
我们会做这样的事情吗?
story--collection-main--features-bottom__author
一定有更好的选择。