You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: document/Sass/docs/04_웹디자이너를_위한_SASS.md
+332Lines changed: 332 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,3 +21,335 @@ Sass와 그 외 CSS 전처리기들은 표준으로 제안할 만한 기능들
21
21
22
22
Sass와 LESS에서 변수가 잘 활용되고 있기 때문에 공식적인 CSS기능으로 변수를 포함하자는 주장이 펼쳐지고 있고, 현재 W3C작업 초안중인 'CSS 변수모듈레벨1'이 개발진행중이며 (http://bkaprt.com/sass/11/) 최신 웹킷 시험버전인 나이틀리 빌즈(Nightly Builds)에서 변수에 대한 지원이 실행되기 시작했습니다.
23
23
24
+
### 미디어쿼리
25
+
26
+
#### 해상도 분기점을 변수로 설정하기
27
+
28
+
```SCSS
29
+
30
+
// 해상도 분기점을 변수로 설정.
31
+
$width-small : 500px;
32
+
$width-medium: 800px;
33
+
$width-large: 1200px;
34
+
35
+
```
36
+
사용 예제 :
37
+
38
+
```SCSS
39
+
40
+
// _style.scss
41
+
42
+
section.main {
43
+
font-size:16px;
44
+
line-height: 1.4;
45
+
46
+
@mediascreenand(max-width: $width-large){
47
+
float: left;
48
+
width: 65%
49
+
}
50
+
@mediascreenand(max-width: $width-medium{
51
+
float: none;
52
+
width: auot;
53
+
}
54
+
@mediascreenand(max-width: $width-small){
55
+
font-size: 12px;
56
+
width: 1.4;
57
+
}
58
+
}
59
+
60
+
```
61
+
컴파일
62
+
63
+
```CSS
64
+
65
+
// _style.css
66
+
67
+
section.main {
68
+
font-size:16px;
69
+
line-height: 1.4;
70
+
}
71
+
@mediascreen and(max-width:1200px){
72
+
float: left;
73
+
width: 65%
74
+
}
75
+
@mediascreen and(max-width: 800px){
76
+
float: none;
77
+
width: auot;
78
+
}
79
+
@mediascreen and(max-width: 500px){
80
+
font-size: 12px;
81
+
width: 1.4;
82
+
}
83
+
84
+
```
85
+
86
+
나중에 해상도 분기점을 수정할 경우 변수값을 딱 한번만 고치면 Sass가 알아서 그 값이 사용된 모든곳을 업데이트 해줄 것입니다.
87
+
연산도 가능해서 해상도 분기점의 값을 더하거나 뺼 수 있습니다.
88
+
89
+
```SCSS
90
+
91
+
// _style.scss
92
+
93
+
94
+
@mediascreen and(max-width: $width-small + 1){
95
+
font-size: 12px;
96
+
width: 1.4;
97
+
}
98
+
@mediascreen and(max-width: $width-small - 1){
99
+
font-size: 12px;
100
+
width: 1.4;
101
+
}
102
+
```
103
+
컴파일
104
+
105
+
```CSS
106
+
107
+
// _style.css
108
+
109
+
@mediascreen and(max-width: 501px){
110
+
font-size: 12px;
111
+
width: 1.4;
112
+
}
113
+
@mediascreen and(max-width: 499px){
114
+
font-size: 12px;
115
+
width: 1.4;
116
+
}
117
+
```
118
+
좀 더 응용해서 미디어쿼리 전체를 변수로 지정할 수도 있습니다.
119
+
120
+
```SCSS
121
+
122
+
// _style.scss
123
+
124
+
$mobile-first: "screen and (min-widht: 300px)";
125
+
126
+
@media #{$movile-first}{
127
+
#content {
128
+
font-size:14px;
129
+
line-height:1.5;
130
+
}
131
+
}
132
+
```
133
+
```CSS
134
+
135
+
// _style.css
136
+
137
+
@mediascreenand (min-widht: 300px){
138
+
#content {
139
+
font-size:14px;
140
+
line-height:1.5;
141
+
}
142
+
}
143
+
```
144
+
145
+
#### @content블록과 믹스인 결합시키기.
146
+
147
+
`@content` 지시자를 사용해서 스타일 블록 전체를 믹스인으로 넘길 수 있습니다.
148
+
Sass는 컴파일 하면서 그 블록을 믹스인을 호출하는 선언 안에 다시 넣을 것 입니다.
149
+
150
+
아래는 예시입니다. 서로다른 3개의 해상도 분기점을 가진 반응형 믹스인을 만들고 각 해상도 분기점에 포함시킬 스타일을 `@content`에 담아 제어합니다.
151
+
152
+
```SCSS
153
+
154
+
$width-small : 400px;
155
+
$width-medium: 760px;
156
+
$width-large: 1200px;
157
+
158
+
@mixin responsive($width){
159
+
@if $width == wide-screens{
160
+
@mediaonlyscreenand ( max-width: $width-large){
161
+
@content;
162
+
}
163
+
}
164
+
@else if $width == medium-screens{
165
+
@mediaonlyscreenand ( max-width: $width-medium){
166
+
@content;
167
+
}
168
+
}
169
+
@else if $width == small-screens{
170
+
@mediaonlyscreenand ( max-width: $width-small){
171
+
@content;
172
+
}
173
+
}
174
+
175
+
}
176
+
177
+
```
178
+
179
+
믹스인을 삽입할 대 넘겨줄 $width 변수의 값을 확인하기 위해 @if와 @else 문을 사용합니다.
180
+
예를 들어 우리가 믹스인에 medium-screen 변수를 넘겨주면 Sass는 $width-medium 변수에 설정한 값인 `760px`을 `max-width`에 넣어 미디어쿼리를 컴파일할 것입니다. `@content`는 더 나아가 미디어쿼리를 삽입할 믹스인에 스타일 블록을 넘겨줄 수 있습니다.
0 commit comments