Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BEM 命名规范 #51

Open
ONE-SUNDAY opened this issue Jul 11, 2017 · 1 comment
Open

BEM 命名规范 #51

ONE-SUNDAY opened this issue Jul 11, 2017 · 1 comment

Comments

@ONE-SUNDAY
Copy link

BEM 其实是块(block)、元素(element)、修饰符(modifier)的缩写,利用不同的区块,功能以及样式来给元素命名。这三个部分使用 __-- 连接(这里用两个而不是一个是为了留下用于块儿的命名)。命名约定的模式如下:

.block {}
.block__element {}
.block--modifier {}
  • block 代表了更高级别的抽象或组件
  • block__element 代表 block 的后代,用于形成一个完整的 block 的整体
  • block--modifier 代表 block 的不同状态或不同版本
.block {
    @at-root #{&}__element {}
    @at-root #{&}--modifier {}
}
/* 生成的CSS */
.block {}
.block__element {}
.block--modifier {}

参考资料:https://mrzhang123.github.io/2017/04/05/BEM/

@afeiship
Copy link

afeiship commented Apr 4, 2018

.block {
  &__element {
    color:#30d;
  }
  &--modifier {
    font-size:12px;
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants