forked from rsms/raster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
585 lines (519 loc) · 19.3 KB
/
index.html
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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
---
layout: none
---
{%
assign version = site.data.info.version %}{%
capture download_url
%}https://github.com/rsms/raster/releases/download/v{{ version }}/Raster-v{{ version }}.zip{%
endcapture %}{%
for file in site.static_files %}{%
assign _path = file.path | remove_first: "/raster" %}{%
if _path == "/res/base.css" %}{%
assign base_css_v = file.modified_time | date: "%Y%m%d%H%M%S" %}{%
elsif _path == "/res/generate-grid.js" %}{%
assign generate_grid_js_v = file.modified_time | date: "%Y%m%d%H%M%S" %}{%
endif %}{%
endfor
%}<html lang="en">
<head>
<meta charset="utf-8">
<title>Raster—CSS Grid System</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="stylesheet" href="raster2.css?v={{version}}">
<script src="raster2.js?v={{version}}"></script>
<link rel="stylesheet" href="res/base.css?v={{base_css_v}}">
</head>
<body>
<r-grid columns="8">
<r-cell span="2" span-s="row">
<h1>
Raster<br>
Simple Grid System
</h1>
<br>
<p>
Minimal and straight-forward CSS grid system
utilizing descriptive HTML rather than semantic CSS.
</p>
<r-grid columns=2>
<r-cell><a class="download-button" href="{{download_url}}">
Download ↓
</a></r-cell>
<r-cell class="center flex-v">
<a href="examples/">Examples</a>
</r-cell>
</r-grid>
<br>
</r-cell>
<r-cell span="3.." span-s="row">
<r-grid columns=8 class="demo">
<r-cell>1</r-cell> <r-cell>2</r-cell> <r-cell>3</r-cell> <r-cell>4</r-cell> <r-cell>5</r-cell> <r-cell>6</r-cell> <r-cell>7</r-cell> <r-cell>8</r-cell>
<r-cell></r-cell>
<r-cell span=3>3</r-cell>
<r-cell></r-cell>
<r-cell span=7-8>7-8</r-cell>
<r-cell span=2+2>2+2</r-cell>
<r-cell span=5-8>5-8</r-cell>
<r-cell span=1-4>1-4</r-cell>
<r-cell span=6..>6..</r-cell>
<r-cell span=2..>2..</r-cell>
<r-cell span=4..>4..</r-cell>
<r-cell span=1-2>1-2</r-cell>
<r-cell span=4-5>4-5</r-cell>
</r-grid>
<br><br>
</r-cell>
<r-cell span="3.." span-s=row class="h2">
Simplicity first
</r-cell>
<r-cell span="1-2" span-s="row">
<pre class="side-sample"><r-grid columns=8>
<r-cell></r-cell>
<r-cell span=3>3</r-cell>
<r-cell></r-cell>
<r-cell span=7-8>7-8</r-cell>
<r-cell span=2+2>2+2</r-cell>
<r-cell span=5-8>5-8</r-cell>
<r-cell span=1-4>1-4</r-cell>
<r-cell span=6..>6..</r-cell>
<r-cell span=2..>2..</r-cell>
<r-cell span=4..>4..</r-cell>
<r-cell span=1-2>1-2</r-cell>
<r-cell span=4-5>4-5</r-cell>
</r-grid></pre>
</r-cell>
<r-cell span="3-6" span-s="row">
<p>
The number of columns a grid has is specified by the
<code>columns</code> attribute.
For instance, to define a grid with 8 columns, you'd write
<code><r-grid columns=8></code>.
</p>
<p>
Cells span a single column by default.
The <code>span</code> attribute is used to customize where a cell
starts and how many columns it spans.
For example, <code><r-cell span=2-5></code> starts in column 2 and ends in column 5.
A cell with an empty or missing <code>span</code> attribute starts on
the next available column and spans one column.
</p>
<p>
Raster is <a href="raster2.css?v={{version}}">pure CSS</a> — no JavaScript involved.
</p>
<p>
The HTML here is what generates the grid you see at the top of this page.
</p>
<p>
<a href="examples/">More examples</a>
</p>
</r-cell>
<r-cell span="7.." span-s="row">
<h4>Possible span= values</h4><br>
<p>
<r-grid columns=8 style="column-gap:1.5rem">
<r-cell><code>2-5</code></r-cell>
<r-cell span=2..>start in column 2,<br>end in column 5.</r-cell>
<r-cell><code>2+3</code></r-cell>
<r-cell span=2..>start in column 2,<br>span 3 columns.</r-cell>
<r-cell><code>2..</code></r-cell>
<r-cell span=2..>start in column 2,<br>span remainder of row.</r-cell>
<r-cell><code>2</code></r-cell>
<r-cell span=2..>start in next column,<br>span 2 columns.</r-cell>
<r-cell><code>row</code></r-cell>
<r-cell span=2..>span a full row</r-cell>
</r-grid>
</p>
</r-cell>
<r-cell span=3.. class="ruler only-large-screen"></r-cell>
<r-cell span=3.. span-s=row class="h2" id="responsive-design">
Responsive design
</r-cell>
<r-cell span=1-2 span-s=row>
<pre class="side-sample"><r-grid columns=6>
<r-cell span=2 <b>span-s=row</b>>
<r-cell span=3-6 <b>span-s=row</b>>
<r-cell span=1-2 <b>span-s=1</b>>
<r-cell span=3.. <b>span-s=2..</b>>
</r-grid></pre><br>
</r-cell>
<r-cell span=3-6 span-s=row>
<p>
Grids lend themselves really well to device-size responsive design.
The <code>span-s</code> attribute defines alternate layout when your
design is presented on a small screen.
This makes designing for large and small screens really easy.
</p>
<r-grid columns=6 class="example" id="example1">
<r-cell span=2 span-s=row class=black>Acme</r-cell>
<r-cell span=3-6 span-s=row>Things About Privacy policy</r-cell>
<r-cell span=1-2 span-s=1 class=black>Image</r-cell>
<r-cell span=3.. span-s=2..>Welcome to Acme</r-cell>
</r-grid>
<p>
Tap the example above—or resize your web browser window—to see the
layout change.
Showing <b id="example1-label1" class="example-label">large</b> screen.
Additionally, the <code>span-l</code> attribute can be used to control
an alternate layout for really large screens.
</p>
<p>
This entire website is built with grids and changes layout when the
window size passes 600dp.
</p>
</r-cell>
<r-cell span=3.. span-s=row class="h3" id="responsive-design">
Additional responsive control with columns-s
</r-cell>
<r-cell span=1-2 span-s=row>
<pre class="side-sample"><r-grid columns=6<br> <b>columns-s=3</b>>
<r-cell>
<r-cell span=2>
<r-cell>
<r-cell span=2>
</r-grid></pre><br>
</r-cell>
<r-cell span=3-6 span-s=row>
<p>
Similar to <code>span-s</code>, <code>columns-s</code> is available
on <code>r-grid</code> tags for alternate layout on small screens.
Often a small-screen layout can be accomplished by simply setting
<code>columns-s</code> without the need for any <code>span-s</code>
attributes. The <code>columns-l</code> attribute is also available
for large screens.
</p>
<r-grid columns=6 columns-s=3 class="example" id="example2">
<r-cell class=black>Foo</r-cell>
<r-cell span=2>Description of foo</r-cell>
<r-cell class=black>Bar</r-cell>
<r-cell span=2>Description of bar</r-cell>
</r-grid>
<p>
Tap the example above—or resize your web browser window—to see the
layout change.
Showing <b id="example2-label1" class="example-label">large</b> screen.
</p>
</r-cell>
<r-cell span=3.. class="ruler only-large-screen"></r-cell>
<r-cell span=3.. span-s=row class="h2" id="responsive-design">
Excellent websites with minimal effort
</r-cell>
<r-cell span=1-2 span-s=row>
<a href="examples/">Example gallery</a>
</r-cell>
<r-cell span=3-6 span-s=row>
<p>
Raster is a complete CSS framework for creating websites.<br>
The Raster system is minimal but complete:
</p>
<ul>
<li>
Provides a simple, minimal and solid starting point for
websites. Get started quickly with the
<a href="template.html">HTML template</a>, or just include
<a href="raster2.css?v={{version}}">raster2.css</a> in your own
HTML.
</li>
<li>
Grids as the foundation assists in creating graphically harmonious
and expressive designs.
</li>
<li>
Good typography and scale harmony out of the box.
</li>
<li>
Easy customization via CSS variables.
For instance, set <code>--fontSize: 18px</code> to change
the entire scale of your website, or fine-tune spacing of various
elements using the <code>--lineHeight</code> variable, which is the
basis for all lengths.
</li>
<li>
<a href="raster2.css?v={{version}}">raster2.css</a> is only 5 kB gzipped
</li>
</ul>
</r-cell>
<r-cell span=3.. class="ruler only-large-screen"></r-cell>
<r-cell span=3.. span-s=row class="h2" id="custom-css">
Customize raster.grid.css
</r-cell>
<r-cell span=3-6 span-s=row>
<p>
<a href="raster.grid.css?v={{version}}">raster.grid.css</a>
provides the minimal set of <code><r-grid></code> functionality.
If you're looking for a complete framework,
use <a href="raster2.css?v={{version}}">raster2.css</a>
instead.
</p>
</r-cell>
<r-cell span=1-2 span-s=row class="only-large-screen form" style="max-width:15rem">
<label><r-grid columns=4>
<r-cell span=1-2>Prefix:</r-cell>
<r-cell span=3-4><input type="text" value="r-" name="tagPrefix" autocomplete="off"></r-cell>
</r-grid></label>
<label><r-grid columns=4>
<r-cell span=1-2>Columns:</r-cell>
<r-cell span=3-4><input type="number" value="8" min=2 max=30 name="maxColumns" autocomplete="off"></r-cell>
</r-grid></label>
<label><r-grid columns=4>
<r-cell span=1-2>Default cols:</r-cell>
<r-cell span=3-4><input type="number" value="4" min=1 max=30 name="defaultColumns" autocomplete="off"></r-cell>
</r-grid></label>
<label><r-grid columns=4>
<r-cell span=1-2>Small window:</r-cell>
<r-cell span=3-4><input type="number" value="600" step="100" min=0 max="10000" name="smallScreenWidth" autocomplete="off"></r-cell>
</r-grid></label>
<label><r-grid columns=4>
<r-cell span=1-2>Large window:</r-cell>
<r-cell span=3-4><input type="number" value="1600" step="100" min=0 max="10000" name="largeScreenWidth" autocomplete="off"></r-cell>
</r-grid></label>
<label><r-grid columns=4>
<r-cell span=1-2>Grid attr:</r-cell>
<r-cell span=3-4><input type="text" value="columns" name="colsAttr" autocomplete="off"></r-cell>
</r-grid></label>
<label><r-grid columns=4>
<r-cell span=1-2>Cell attr:</r-cell>
<r-cell span=3-4><input type="text" value="span" name="spanAttr" autocomplete="off"></r-cell>
</r-grid></label>
<label><r-grid columns=4>
<r-cell span=1-2>Small suffix:</r-cell>
<r-cell span=3-4><input type="text" value="-s" name="smallAttrSuffix" autocomplete="off"></r-cell>
</r-grid></label>
<label><r-grid columns=4>
<r-cell span=1-2>Large suffix:</r-cell>
<r-cell span=3-4><input type="text" value="-l" name="largeAttrSuffix" autocomplete="off"></r-cell>
</r-grid></label>
<label>
<input type="checkbox" name="includeDebug" checked>
<span>Include .debug</span>
</label>
<br>
<p>
This CSS generator is also available as a script:
<a href="res/generate-grid.js">generate-grid.js</a>
</p>
</r-cell>
<r-cell span="3.." span-s="row">
<div class="code-area">
<div class="overlay"></div>
<textarea class="code" id="css-output" autocomplete="off" spellcheck="false" readonly></textarea>
</div>
<h3>Open source</h3>
<p>
Raster is an open-source project and the
<a href="https://github.com/rsms/raster">source code is available on GitHub →</a>
</p>
<script src="res/generate-grid.js?v={{generate_grid_js_v}}"></script>
<script>(function(){
let cssOutput = document.querySelector('#css-output')
let inputs = {
tagPrefix: document.querySelector('input[name="tagPrefix"]'),
// minColumns: document.querySelector('input[name="minColumns"]'),
maxColumns: document.querySelector('input[name="maxColumns"]'),
defaultColumns: document.querySelector('input[name="defaultColumns"]'),
smallScreenWidth: document.querySelector('input[name="smallScreenWidth"]'),
largeScreenWidth: document.querySelector('input[name="largeScreenWidth"]'),
colsAttr: document.querySelector('input[name="colsAttr"]'),
spanAttr: document.querySelector('input[name="spanAttr"]'),
smallAttrSuffix: document.querySelector('input[name="smallAttrSuffix"]'),
largeAttrSuffix: document.querySelector('input[name="largeAttrSuffix"]'),
includeDebug: document.querySelector('input[name="includeDebug"]'),
}
let values = {
tagPrefix: 'r-',
// minColumns: parseInt(inputs.minColumns.value),
maxColumns: parseInt(inputs.maxColumns.value),
defaultColumns: parseInt(inputs.defaultColumns.value),
smallScreenWidth: parseInt(inputs.smallScreenWidth.value),
largeScreenWidth: parseInt(inputs.largeScreenWidth.value),
spanAttrNormal: 'span',
spanAttrSmall: 'span-s',
spanAttrLarge: 'span-l',
colsAttrNormal: 'columns',
colsAttrSmall: 'columns-s',
colsAttrLarge: 'columns-l',
includeDebug: inputs.includeDebug.checked,
}
function bindNumberInput(name, onchange) {
let input = inputs[name]
let f = ev => {
let v = parseInt(input.value)
if (!isNaN(v) && values[name] != v) {
values[name] = v
if (onchange) {
let v2 = onchange(v)
if (v2 !== undefined && v2 != v) {
values[name] = v2
input.value = v2
}
}
genCSS()
}
}
input.addEventListener('input', f)
input.addEventListener('change', f)
}
function updateColsAttr() {
let attr = inputs.colsAttr.value
values['colsAttrNormal'] = attr
values['colsAttrSmall'] = attr + inputs.smallAttrSuffix.value
values['colsAttrLarge'] = attr + inputs.largeAttrSuffix.value
genCSS()
}
function updateSpanAttr() {
let attr = inputs.spanAttr.value
values['spanAttrNormal'] = attr
values['spanAttrSmall'] = attr + inputs.smallAttrSuffix.value
values['spanAttrLarge'] = attr + inputs.largeAttrSuffix.value
genCSS()
}
function updateAttrs() {
updateColsAttr()
updateSpanAttr()
}
inputs.colsAttr.addEventListener('input', updateColsAttr)
inputs.colsAttr.addEventListener('change', updateColsAttr)
inputs.spanAttr.addEventListener('input', updateSpanAttr)
inputs.spanAttr.addEventListener('change', updateSpanAttr)
inputs.smallAttrSuffix.addEventListener('input', updateAttrs)
inputs.smallAttrSuffix.addEventListener('change', updateAttrs)
inputs.largeAttrSuffix.addEventListener('input', updateAttrs)
inputs.largeAttrSuffix.addEventListener('change', updateAttrs)
inputs.tagPrefix.addEventListener('input', ev => {
values.tagPrefix = inputs.tagPrefix.value
genCSS()
})
inputs.includeDebug.addEventListener('change', ev => {
values.includeDebug = inputs.includeDebug.checked
genCSS()
})
// bindNumberInput('minColumns', minColumns => {
// minColumns = Math.min(Math.max(2, minColumns), 30)
// if (minColumns > values.maxColumns) {
// inputs.maxColumns.value = values.maxColumns = minColumns
// }
// return minColumns
// })
bindNumberInput('maxColumns', maxColumns => {
maxColumns = Math.min(Math.max(2, maxColumns), 30)
if (maxColumns < values.minColumns) {
inputs.minColumns.value = values.minColumns = maxColumns
}
return maxColumns
})
bindNumberInput('defaultColumns', defaultColumns => {
defaultColumns = Math.min(Math.max(1, defaultColumns), 30)
if (defaultColumns > values.maxColumns) {
return values.maxColumns
}
return defaultColumns
})
bindNumberInput('smallScreenWidth')
bindNumberInput('largeScreenWidth')
function genCSS() {
let css = Raster.generateCSS(values)
cssOutput.value = css
// cssOutput.scrollTop = 0
// cssOutput.scrollTo(0,0)
}
let cssOutputScrolled = false
cssOutput.addEventListener('scroll', ev => {
if (!cssOutputScrolled && cssOutput.scrollTop > 0) {
cssOutputScrolled = true
cssOutput.classList.add('scrolled')
} else if (cssOutputScrolled && cssOutput.scrollTop <= 0) {
cssOutputScrolled = false
cssOutput.classList.remove('scrolled')
}
}, {passive:true, capture:false})
cssOutput.addEventListener(
'PointerEvent' in window ? 'pointerup' : 'click',
ev => {
cssOutput.select()
// document.execCommand("copy")
}
)
genCSS()
})()</script>
</r-cell>
<r-cell span=row class="ruler"></r-cell>
<r-cell span=row class="h3" id="custom-css">
<br>
<a href="examples/">Explore the example gallery →</a>
<br>
<br>
</r-cell>
<r-cell span=row>
<a href="https://rsms.me/" class="clean">@rsms</a>
</r-cell>
</r-grid>
<div id="smallScreenBeacon"></div>
<script>(function(){
// debug grid
let sg = document.querySelector('r-grid.demo')
sg.style.position = 'relative'
let dg = sg.cloneNode(false)
dg.classList.remove('demo')
dg.classList.add('debug-lines')
for (let col = 0; col < 8; col++) {
let c = document.createElement('r-cell')
c.innerHTML = ' '
dg.appendChild(c)
}
sg.appendChild(dg)
// smallScreenBeacon
let smallScreenBeacon = document.querySelector('#smallScreenBeacon')
function isSmallScreen() {
return !!parseInt(window.getComputedStyle(smallScreenBeacon).width)
}
// example1 -- span-s simulator
let triggerEvent = 'PointerEvent' in window ? 'pointerdown' : 'click'
let exampleCount = 2
for (let i = 0; i < exampleCount; i++) {
let example = document.querySelector(`#example${i+1}`)
let exampleLabel1 = document.querySelector(`#example${i+1}-label1`)
let exampleIsFlipped = false
function updateExample1Label1() {
let isSmall = exampleIsFlipped ? !isSmallScreen() : isSmallScreen()
exampleLabel1.innerText = isSmall ? 'small' : 'large'
}
updateExample1Label1()
let winResizeTimer = null
window.addEventListener('resize', () => {
clearTimeout(winResizeTimer)
winResizeTimer = setTimeout(() => {
updateExample1Label1()
}, 200)
})
let flashTimer = null
example.addEventListener(triggerEvent, ev => {
exampleIsFlipped = !exampleIsFlipped
updateExample1Label1()
clearTimeout(flashTimer)
exampleLabel1.classList.add('flash')
flashTimer = setTimeout(() => {
exampleLabel1.classList.remove('flash')
}, 380)
let colsS = example.getAttribute('columns-s')
let colsM = example.getAttribute('columns')
if (colsS !== null && colsM !== null) {
example.setAttribute('columns', colsS)
example.setAttribute('columns-s', colsM)
}
for (let i = 0; i < example.children.length; i++) {
let c = example.children[i]
// if (c.tagName != 'C') { continue }
let spanS = c.getAttribute('span-s')
let spanM = c.getAttribute('span')
if (spanS !== null && spanM !== null) {
c.setAttribute('span', spanS)
c.setAttribute('span-s', spanM)
}
}
})
}
})()</script>
{% include analytics.html %}
</body>
</html>