我们可以在BEM中制作块修改器的元素吗? [英] Can we make an element of block modifier in BEM?

查看:70
本文介绍了我们可以在BEM中制作块修改器的元素吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道以下代码是否遵循BEM方法论的最佳实践?为block修改器创建一个元素,即在这种情况下, block--mod是 block块的修改器。是否可以使用以下模式创建嵌套元素: block--mod__elm。

I just wanted to know whether the following code follows BEM methodology best practices? Creating an element for the block modifier i.e. in this case "block--mod" is a modifier for the "block" block. Is it allowed to create a nested element with this pattern: "block--mod__elm".

<div class="block block--mod">
   <div class="block__elm block--mod__elm">
</div>


推荐答案

在主题化或类似情况下,我会使用嵌套选择器。这样可以在HTML中保存一些类,就像@Jonathan Nicol所说的那样,这些子元素可能很难理解。另外,以后删除烙印会更容易,只需删除块类而不是其所有元素即可。

In situations like theming or similar I would use nested selectors. This saves some classes in your HTML and as @Jonathan Nicol said those sub-elements can be hard to follow. Also it will be easier to remove the "branding" later, just remove block class instead of all it's elements.

例如标头的圣诞节烙印。

For example Xmas branding of your header.

.header--xmas .header__logo {
    /* Jingle bells, jingle bells, jingle all the way.*/
}

来源: http://getbem.com/faq/#can-a-block-modifier-affect-elements-

这篇关于我们可以在BEM中制作块修改器的元素吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆