-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path01-nesting.scss
65 lines (46 loc) · 1.41 KB
/
01-nesting.scss
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
// NESTING
// EXAMPLE 1: HELPS YOU GROUP STYLES TOGETHER (SIMILAR TO CLASS NAMESPACING)
// ==========================================================================
form.simple_form {
// everything within these curly brackets will be applied to elements within form with a class of simple_form
}
// Ruby HAML
// %body{:class => "#{controller_name} #{action_name}"}
body.users {
// everything will be applied to the users controller views
}
// EXAMPLE 2: ALLOWS YOU TO AVOID SELECTOR DUPLICATION
// ==========================================================================
// SCSS
table {
tr:nth-child(2n) { background: #eceeea; }
th, td { padding: 10px;
p { color: #555; }
}
}
// css output
table tr:nth-child(2n) { background: #eceeea; }
table th, table td { padding: 10px; }
table th p { color: #555; }
table td p { color: #555; }
// EXAMPLE 3: USING THE PARENT SELECTOR (&) TO REFER BACK TO THE PARENT
// ==========================================================================
p { color: #000;
&.success { color: green; }
&.failure { color: red; }
}
// another example for a good & usage:
a { color: #999; border-bottom: 1px dashed #ccc;
&:hover { text-decoration: none; }
}
// with modernizr and IE
.menu-item {
display: inline-block;
.ltie8 & {
display: inline;
zoom: 1;
}
}
// css output
.menu-item { display: inline-block; }
.ltie8 .menu-item { display: inline ; zoom: 1; }