-
Notifications
You must be signed in to change notification settings - Fork 0
/
BEM.txt
107 lines (69 loc) · 2.78 KB
/
BEM.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*Block
Encapsulates a standalone entity that is meaningful on its own. While blocks can be nested and interact with each other, semantically they remain equal; there is no precedence or hierarchy. Holistic entities without DOM representation (such as controllers or models) can be blocks as well.*/
/*Naming
Block names may consist of Latin letters, digits, and dashes. To form a CSS class, add a short prefix for namespacing: .block*/
/*HTML
Any DOM node can be a block if it accepts a class name.
*/
<div class="block">...</div>
/*CSS
Use class name selector only
No tag name or ids
No dependency on other blocks/elements on a page
*/
.block { color: #042; }
/*Element
Parts of a block and have no standalone meaning. Any element is semantically tied to its block.
Naming
Element names may consist of Latin letters, digits, dashes and underscores. CSS class is formed as block name plus two underscores plus element name: .block__elem
HTML
Any DOM node within a block can be an element. Within a given block, all elements are semantically equal.
*/
<div class="block">
...
<span class="block__elem"></span>
</div>
/*CSS
Use class name selector only
No tag name or ids
No dependency on other blocks/elements on a page
*/
/*Good*/
.block__elem { color: #042; }
/*Bad*/
.block .block__elem { color: #042; }
div.block__elem { color: #042; }
/*
Modifier
Flags on blocks or elements. Use them to change appearance, behavior or state.
Naming
Modifier names may consist of Latin letters, digits, dashes and underscores. CSS class is formed as block’s or element’s name plus two dashes: .block--mod or .block__elem--mod and .block--color-black with .block--color-red. Spaces in complicated modifiers are replaced by dash.
HTML
Modifier is an extra class name which you add to a block/element DOM node. Add modifier classes only to blocks/elements they modify, and keep the original class:*/
/*Good*/
<div class="block block--mod">...</div>
<div class="block block--size-big
block--shadow-yes">...</div>
/*Bad*/
<div class="block--mod">...</div>
/*CSS
Use modifier class name as selector:*/
.block--hidden { }
/*To alter elements based on a block-level modifier:*/
.block--mod .block__elem { }
/*Element modifier:*/
.block__elem--mod { }
Example
/* Suppose you have block form with modifiers theme: "xmas" and simple: true and with elements input and submit, and element submit with its own modifier disabled: true for not submitting form while it is not filled:*/
/*HTML*/
<form class="form form--theme-xmas form--simple">
<input class="form__input" type="text" />
<input class="form__submit form__submit--disabled" type="submit" />
</form>
/*CSS*/
.form { }
.form--theme-xmas { }
.form--simple { }
.form__input { }
.form__submit { }
.form__submit--disabled { }