-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
220 lines (184 loc) · 4.5 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
<!DOCTYPE html>
<title>GridMaker by Youness Belfkih</title>
<style>
body {
margin:0;
font: 10px sans-serif;
background-color: #333;
}
:focus {outline: none;}
.settings {
padding: 5px;
background-image: linear-gradient(#AAA, #888);
text-align: center;
border-top: 1px solid #DDD;
border-bottom: 1px solid #555;
}
.settings input {
border: 1px solid #999;
box-shadow: inset 0 0 5px rgba(0,0,0,.3);
padding: 2px;
border-radius: 2px;
}
.settings input:focus {
background-color: #FFD;
}
::selection {
background-color: #CEF;
}
.settings label {
text-shadow: 0 1px 1px rgba(255,255,255,.3);
-webkit-user-select: none;
}
.code {
box-shadow: inset 0 0 5px rgba(0,0,0,.5);
border: 1px solid #999;
padding: 5px;
font: 14px monospace;
background-color: white;
}
.result {
-webkit-user-select: none;
padding: 0px;
padding-top: 20px;
padding-bottom: 25px;
background-color: #DDD;
border-top: 1px solid #EEE;
border-bottom: 1px solid #CCC;
}
.result .container {
width: 1024px;
margin: auto;
padding: 0 5px;
box-sizing: border-box;
background-color: white;
}
.result .row {
display: block;
}
.result .row::after,
.result .row::before {
clear: both;
content: "";
display: table;
}
.result [class^="col-"] {
box-sizing: border-box;
margin: 0 5px;
padding: 5px;
float: left;
background-color: #FEE;
border: 1px solid #FAA;
}
</style>
<form id="settings" class="settings">
<label for="container_width">Container width:</label></dt>
<input id="container_width" type="number" autofocus value="1024" min="400" step="10" />
<label for="spacing">Spacing:</label>
<input id="spacing" type="number" value="10" step="2" min="0" />
<label for="column_count">Number of columns:</label>
<input id="column_count" type="number" value="6" step="2" min="2" />
</form>
<section class="result">
<div id="container" class="container">
</div>
</section>
<div class="code"><pre id="code"></pre></div>
<script>
(function () {
var state = window.s = {container_width: 1024, spacing: 10, column_count: 6};
var header = '/**\n\
* css grid made with GridMaker 2015, created by Youness Belfkih\n\
* http://xooxdoo.github.io/GridMaker/\n\
*/\n';
var form = document.getElementById('settings');
var container = document.getElementById('container');
var code = document.getElementById('code');
form.onchange = function (e) {
state[e.target.id] = parseInt(e.target.value);
generate();
};
function unitWidth() {
return (state.container_width-(state.spacing*(state.column_count+1)))/state.column_count;
}
function columnWidth (size, unit, spacing) {
return size*unit+(size-1)*spacing;
}
function styleElement (element, size, unit, spacing) {
var width = columnWidth(size, unit, spacing);
element.style.width = width+"px";
element.style.margin = "0 "+(spacing/2)+"px";
}
function emptyDOM () {
container.innerHTML = "";
}
function generateCSS () {
var css = header;
css += generateContainerCSS();
css += generateRowCSS();
css += generateColumnCSS();
var unit = unitWidth();
for (var size = 1; size <= state.column_count; size++) {
css += generateSpecialColumnCSS(unit, size);
}
code.innerText = css;
}
function generate() {
var unit = unitWidth();
emptyDOM();
for (var i = 1; i <= state.column_count; i++) {
var row = container.appendChild(document.createElement("div"));
row.classList.add("row");
var rest = state.column_count;
while (rest > 0) {
var size = i;
if (rest - i < 0) {
size = rest;
}
var element = row.appendChild(document.createElement("div"));
element.classList.add("col-"+size);
element.innerText = "column "+size;
styleElement(element, size, unit, state.spacing)
rest -= size;
}
}
container.style.width = state.container_width+"px";
container.style.padding = "0 "+(state.spacing/2)+"px";
generateCSS();
}
function generateContainerCSS () {
return '\n.container {\n\
width: '+state.container_width+'px;\n\
margin: auto;\n\
padding: 0 '+(state.spacing/2)+'px;\n\
box-sizing: border-box;\n\
}\n';
}
function generateColumnCSS () {
return '\n[class^="col-"] {\n\
box-sizing: border-box;\n\
margin: 0 5px;\n\
float: left;\n\
}';
}
function generateRowCSS() {
return '\n.row {\n\
display: block;\n\
}\n\n\
.row::after,\n\
.row::before {\n\
clear: both;\n\
content: "";\n\
display: table;\n\
}';
}
function generateSpecialColumnCSS (unit, size) {
var width = columnWidth(size, unit, state.spacing);
return '\n.col-'+size+' {\n\
width: '+width.toFixed(2)+'px;\n\
margin: 0 '+(state.spacing/2)+'px;\n\
}\n';
}
generate();
})();
</script>