【发布时间】:2015-03-09 18:53:14
【问题描述】:
给定以下 BEM 树结构,其中存在五个嵌套级别:
collection-main__features-top__story__byline__author
根据 BEM 的命名约定,元素是块的一部分并且在它所属的块之外没有任何意义,那么命名 author 类的正确方法是什么?
由于author 在语义上与byline 和story 上下文相关,但在features-top 和collection-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
一定有更好的选择。
【问题讨论】:
-
请显示您的数据输出。像
{collection-main: [{"feature-item": { story: {author: ''} } }]}吗?
标签: css naming-conventions bem