-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathautoplacement.html
168 lines (153 loc) · 5.5 KB
/
autoplacement.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
<!DOCTYPE html>
<html>
<head>
<link href="css/grid.css" rel="stylesheet">
<style>
body {
font-family: Helvetica, Arial, sans-serif;
margin: 0;
padding: 0;
}
.grid {
margin: 50px;
float: left;
-ms-grid-columns: 150px 150px 150px;
grid-definition-columns: 150px 150px 150px;
grid-template-columns: 150px 150px 150px;
-ms-grid-rows: 75px 75px 75px;
grid-definition-rows: 75px 75px 75px;
grid-template-rows: 75px 75px 75px;
grid-auto-flow: row;
-grid-auto-columns: 150px;
grid-auto-columns: 150px;
-grid-auto-rows: 75px;
grid-auto-rows: 75px;
}
#table {
position: absolute;
top: 50px;
left: 50px;
border-collapse: collapse;
width: 450px;
height: 225px;
}
#table tr {
height: 75px;
}
#table td {
border: 2px dashed grey;
width: 150px;
}
#new {
padding-left: 25px;
}
.grid div {
width: 100%;
height: 100%;
}
</style>
<script>
function randomColor() {
return "#" + Math.floor(Math.random() * 16777215).toString(16);
}
function addGridItem() {
var grid = document.getElementById("grid");
var row = document.getElementById("row");
var rowspan = document.getElementById("rowspan");
var column = document.getElementById("column");
var columnspan = document.getElementById("columnspan");
var item = document.createElement("div");
item.style.msGridRow = row.value + " / span " + rowspan.value;
item.style.webkitGridRow = row.value + " / span " + rowspan.value;
item.style.gridRow = row.value + " / span " + rowspan.value;
item.style.msGridColumn = column.value + " / span " + columnspan.value;
item.style.webkitGridColumn = column.value + " / span " + columnspan.value;
item.style.gridColumn = column.value + " / span " + columnspan.value;
item.style.backgroundColor = randomColor();
item.innerHTML = "<pre> grid-row:\n " + row.value + " / span " + rowspan.value +
"\n grid-column:\n " + column.value + " / span " + columnspan.value + "</pre>";
grid.appendChild(item);
}
function addRandomGridItem() {
var row = document.getElementById("row");
var rowspan = document.getElementById("rowspan");
var column = document.getElementById("column");
var columnspan = document.getElementById("columnspan");
row.selectedIndex = Math.floor(Math.random() * row.options.length);
rowspan.selectedIndex = Math.floor(Math.random() * rowspan.options.length);
column.selectedIndex = Math.floor(Math.random() * column.options.length);
columnspan.selectedIndex = Math.floor(Math.random() * columnspan.options.length);
addGridItem();
}
function updateGridAutoFlow() {
var grid = document.getElementById("grid");
var flow = document.getElementById("flow");
grid.style.webkitGridAutoFlow = flow.value;
grid.style.gridAutoFlow = flow.value;
}
</script>
</head>
<body>
<div id="grid" class="grid">
</div>
<div style="clear: both;"></div>
<div id="new">
<h2>CSS Grid Layout: <a href="http://dev.w3.org/csswg/css-grid/#auto-placement-algo">Grid Item Placement Algorithm</a></h2>
<p>Property <a href="http://dev.w3.org/csswg/css-grid/#grid-auto-flow-property"><code>grid-auto-flow</code></a> is
<select id="flow" onchange="updateGridAutoFlow();">
<option value="row" selected>row</option>
<option value="column">column</option>
<option value="row dense">row dense</option>
<option value="column dense">column dense</option>
</select>
</p>
<p>New grid item at
row
<select id="row">
<option value="auto" selected>auto</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
spanning
<select id="rowspan">
<option value="1" selected>1 row</option>
<option value="2">2 rows</option>
<option value="3">3 rows</option>
</select>
and column
<select id="column">
<option value="auto" selected>auto</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
spanning
<select id="columnspan">
<option value="1" selected>1 column</option>
<option value="2">2 columns</option>
<option value="3">3 columns</option>
</select>
</p>
<button onClick="addGridItem();">Add</button>
<button onClick="addRandomGridItem();">Add random</button>
</div>
<table id="table">
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</table>
</body>
</html>