-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathtypecsset.scss
352 lines (257 loc) · 7.55 KB
/
typecsset.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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
/**
* Typecsset
*
* Typecsset is a small, unopinionated library for creating beautifully set type
* on the web. Typecsset gives perfect vertical rhythm at any configurable font
* size, as well as many other typographical niceties.
*/
//------------------------------------\\
// SETTINGS
//------------------------------------\\
// Typecsset needs some variables setting before it can get started. Some of
// these variables can be overriden by developers, others need to remain
// untouched because Typecsset will assign them automatically based on what
// you’ve told it.
// What would you like your base font-size to be? Define in pixels; the library
// will convert measurements to the most appropriate units (rems or unitless).
$typecsset-base-font-size: 16px !default;
$typecsset-base-line-height: 24px !default;
// Heading sizes
$typecsset-h1-size: 48px !default;
$typecsset-h2-size: 36px !default;
$typecsset-h3-size: 30px !default;
$typecsset-h4-size: 24px !default;
$typecsset-h5-size: 20px !default;
$typecsset-h6-size: 18px !default;
// Would you like indented (rather than spaced) paragraph delimiting?
$typecsset-indented-paragraphs: false !default;
// Would you like to show a baseline grid? This is handy during development.
$typecsset-show-baseline: false !default;
// Do not modify these variables; they are internal settings upon which the
// library depends.
$typecsset-magic-number: $typecsset-base-line-height;
$typecsset-magic-ratio: $typecsset-base-line-height / $typecsset-base-font-size;
//------------------------------------\\
// TOOLS
//------------------------------------\\
// Typecsset has a number of its own tools which it uses to generate its CSS
// more efficiently.
// Quickly generate a font-size in rems, with a pixel fallback, based on the
// value we pass into the mixin, e.g.:
//
// h1 {
// @include typecsset-font-size(24px);
// }
//
@mixin typecsset-font-size($font-size, $line-height: true) {
font-size: $font-size;
font-size: ($font-size / $typecsset-base-font-size) * 1rem;
@if $line-height == true {
line-height: ceil($font-size / $typecsset-base-line-height) * ($typecsset-base-line-height / $font-size);
}
}
// Space elements by an amount based on your magic number. Pass in the property
// to be indented as a paramater, e.g.:
//
// pre {
// @include typecsset-space(padding-left);
// }
//
@mixin typecsset-space($property) {
#{$property}: 2 * $typecsset-magic-number;
#{$property}: 2 * $typecsset-magic-ratio + rem;
}
// A small, internally-used function to remove the units from a given value.
@function typecsset-strip-units($number) {
@return $number / ($number * 0 + 1);
}
/*------------------------------------*\
#SHARED
\*------------------------------------*/
/**
* A lot of elements in Typecsset need to share some declarations (mainly for
* vertical rhythm), so we `@extend` some silent classes.
*/
%typecsset-reset {
margin: 0;
padding: 0;
}
%typecsset-vertical-rhythm {
@extend %typecsset-reset;
margin-bottom: $typecsset-magic-number;
margin-bottom: $typecsset-magic-ratio + rem;
}
/*------------------------------------*\
#BASE
\*------------------------------------*/
/**
* 1. Set the base element’s `font-size` to the value of your choosing. Set in
* ems, assuming a browser default of 16px.
* 2. Work out the unitless `line-height` for your project based around your
* desired `line-height` (defined previously in pixels), and your project’s
* base font size.
*/
@if $typecsset-show-baseline == true {
/**
* 3. If you have chosen to display a baseline grid, we turn it on here.
*/
}
html {
font-size: $typecsset-base-font-size / 16px + em; /* [1] */
line-height: $typecsset-base-line-height / $typecsset-base-font-size; /* [2] */
// If you have chosen to display a baseline grid, we turn it on here.
@if $typecsset-show-baseline == true {
$typecsset-baseline-size: typecsset-strip-units($typecsset-magic-number);
background-image: url(http://basehold.it/i/#{$typecsset-baseline-size}); /* [3] */
}
}
body {
margin: 0;
}
/*------------------------------------*\
#HEADINGS
\*------------------------------------*/
h1 {
@extend %typecsset-vertical-rhythm;
@include typecsset-font-size($typecsset-h1-size);
}
h2 {
@extend %typecsset-vertical-rhythm;
@include typecsset-font-size($typecsset-h2-size);
}
h3 {
@extend %typecsset-vertical-rhythm;
@include typecsset-font-size($typecsset-h3-size);
}
h4 {
@extend %typecsset-vertical-rhythm;
@include typecsset-font-size($typecsset-h4-size);
}
h5 {
@extend %typecsset-vertical-rhythm;
@include typecsset-font-size($typecsset-h5-size);
}
h6 {
@extend %typecsset-vertical-rhythm;
@include typecsset-font-size($typecsset-h6-size);
}
/*------------------------------------*\
#LISTS
\*------------------------------------*/
ul, ol, dd {
@extend %typecsset-vertical-rhythm;
@include typecsset-space(margin-left);
}
li > ul,
li > ol {
margin-bottom: 0;
}
/*------------------------------------*\
#PARAGRAPHS
\*------------------------------------*/
p {
@extend %typecsset-vertical-rhythm;
@if $typecsset-indented-paragraphs == true {
+ p {
@include typecsset-space(text-indent);
margin-top: -$typecsset-magic-number;
margin-top: -$typecsset-magic-ratio + rem;
}
}
}
/**
* Not strictly a paragraph, but probably doesn’t need its own section.
*/
address {
@extend %typecsset-vertical-rhythm;
}
/*------------------------------------*\
#CODE
\*------------------------------------*/
pre {
@extend %typecsset-vertical-rhythm;
}
/**
* 1. Fix an odd quirk whereby, without this, code blocks are rendered at a
* font-size smaller than 1em.
*/
code,
kbd,
pre,
samp {
font-family: monospace, monospace; /* [1] */
}
/*------------------------------------*\
#QUOTES
\*------------------------------------*/
/**
* 1. Hang the opening quote of the blockquote.
*/
blockquote {
text-indent: -0.41em; /* [1] */
}
/**
* Set up quote marks on quoting elements. This is very English-based, so we are
* using “, ”, ‘, and ’ quotes.
*/
blockquote {
@extend %typecsset-vertical-rhythm;
quotes: "“" "”";
@include typecsset-space(margin-left);
p {
&:before {
content: "“";
content: open-quote;
}
&:after {
content: "";
content: no-close-quote;
}
&:last-of-type:after {
content: "”";
content: close-quote;
}
}
}
q {
quotes: "‘" "’" "“" "”";
&:before {
content: "‘";
content: open-quote;
}
&:after {
content: "’";
content: close-quote;
}
q:before {
content: "“";
content: open-quote;
}
q:after{
content: "”";
content: close-quote;
}
/**
* If an element opens with an inline quote, let’s hang that.
*/
&:first-child {
display: inline-block;
text-indent: -0.22em;
}
}
/*------------------------------------*\
#TABLES
\*------------------------------------*/
/**
* Crude table styles; tables are very difficult to keep on the baseline.
*/
table {
@extend %typecsset-vertical-rhythm;
width: 100%;
border-collapse: collapse;
border-spacing: 0;
}
th,
td {
padding: $typecsset-base-line-height / 2;
}