|
| 1 | +<!DOCTYPE html> |
| 2 | +<html> |
| 3 | +<head> |
| 4 | + <link href="css/grid.css" rel="stylesheet"> |
| 5 | + <style> |
| 6 | + body { |
| 7 | + font-family: Helvetica, Arial, sans-serif; |
| 8 | + margin: 0; |
| 9 | + padding: 0; |
| 10 | + } |
| 11 | + |
| 12 | + .grid { |
| 13 | + margin: 50px; |
| 14 | + float: left; |
| 15 | + -ms-grid-columns: 150px 150px 150px; |
| 16 | + -webkit-grid-definition-columns: 150px 150px 150px; |
| 17 | + -webkit-grid-template-columns: 150px 150px 150px; |
| 18 | + grid-definition-columns: 150px 150px 150px; |
| 19 | + grid-template-columns: 150px 150px 150px; |
| 20 | + -ms-grid-rows: 75px 75px 75px; |
| 21 | + -webkit-grid-definition-rows: 75px 75px 75px; |
| 22 | + -webkit-grid-template-rows: 75px 75px 75px; |
| 23 | + grid-definition-rows: 75px 75px 75px; |
| 24 | + grid-template-rows: 75px 75px 75px; |
| 25 | + -webkit-grid-auto-flow: row; |
| 26 | + grid-auto-flow: row; |
| 27 | + -grid-auto-columns: 150px; |
| 28 | + grid-auto-columns: 150px; |
| 29 | + -grid-auto-rows: 75px; |
| 30 | + grid-auto-rows: 75px; |
| 31 | + } |
| 32 | + |
| 33 | + #table { |
| 34 | + position: absolute; |
| 35 | + top: 50px; |
| 36 | + left: 50px; |
| 37 | + border-collapse: collapse; |
| 38 | + width: 450px; |
| 39 | + height: 225px; |
| 40 | + } |
| 41 | + |
| 42 | + #table tr { |
| 43 | + height: 75px; |
| 44 | + } |
| 45 | + |
| 46 | + #table td { |
| 47 | + border: 2px dashed grey; |
| 48 | + width: 150px; |
| 49 | + } |
| 50 | + |
| 51 | + #new { |
| 52 | + padding-left: 25px; |
| 53 | + } |
| 54 | + </style> |
| 55 | + <script> |
| 56 | + function randomColor() { |
| 57 | + return "#" + Math.floor(Math.random() * 16777215).toString(16); |
| 58 | + } |
| 59 | + |
| 60 | + function addGridItem() { |
| 61 | + var grid = document.getElementById("grid"); |
| 62 | + var row = document.getElementById("row"); |
| 63 | + var rowspan = document.getElementById("rowspan"); |
| 64 | + var column = document.getElementById("column"); |
| 65 | + var columnspan = document.getElementById("columnspan"); |
| 66 | + |
| 67 | + var item = document.createElement("div"); |
| 68 | + item.style.gridRow = row.value + " / span " + rowspan.value; |
| 69 | + item.style.gridColumn = column.value + " / span " + columnspan.value; |
| 70 | + item.style.backgroundColor = randomColor(); |
| 71 | + |
| 72 | + item.innerHTML = "<pre> grid-row:\n " + item.style.gridRowStart + " / " + item.style.gridRowEnd + |
| 73 | + "\n grid-column:\n " + item.style.gridColumnStart + " / " + item.style.gridColumnEnd + "</pre>"; |
| 74 | + |
| 75 | + grid.appendChild(item); |
| 76 | + } |
| 77 | + |
| 78 | + function addRandomGridItem() { |
| 79 | + var row = document.getElementById("row"); |
| 80 | + var rowspan = document.getElementById("rowspan"); |
| 81 | + var column = document.getElementById("column"); |
| 82 | + var columnspan = document.getElementById("columnspan"); |
| 83 | + |
| 84 | + row.selectedIndex = Math.floor(Math.random() * 4); |
| 85 | + rowspan.selectedIndex = Math.floor(Math.random() * 3); |
| 86 | + column.selectedIndex = Math.floor(Math.random() * 4); |
| 87 | + columnspan.selectedIndex = Math.floor(Math.random() * 3); |
| 88 | + |
| 89 | + addGridItem(); |
| 90 | + } |
| 91 | + </script> |
| 92 | +</head> |
| 93 | +<body> |
| 94 | + <div id="grid" class="grid"> |
| 95 | + </div> |
| 96 | + <div style="clear: both;"></div> |
| 97 | + <div id="new"> |
| 98 | + <h2>CSS Grid Layout Auto-placement Algorithm</h2> |
| 99 | + <p>New grid item at |
| 100 | + row |
| 101 | + <select id="row"> |
| 102 | + <option value="auto" selected>auto</option> |
| 103 | + <option value="1">1</option> |
| 104 | + <option value="2">2</option> |
| 105 | + <option value="3">3</option> |
| 106 | + </select> |
| 107 | + spanning |
| 108 | + <select id="rowspan"> |
| 109 | + <option value="1" selected>1 row</option> |
| 110 | + <option value="2">2 rows</option> |
| 111 | + <option value="3">3 rows</option> |
| 112 | + </select> |
| 113 | + and column |
| 114 | + <select id="column"> |
| 115 | + <option value="auto" selected>auto</option> |
| 116 | + <option value="1">1</option> |
| 117 | + <option value="2">2</option> |
| 118 | + <option value="3">3</option> |
| 119 | + </select> |
| 120 | + spanning |
| 121 | + <select id="columnspan"> |
| 122 | + <option value="1" selected>1 column</option> |
| 123 | + <option value="2">2 columns</option> |
| 124 | + <option value="3">3 columns</option> |
| 125 | + </select> |
| 126 | + </p> |
| 127 | + <button onClick="addGridItem();">Add</button> |
| 128 | + <button onClick="addRandomGridItem();">Add random</button> |
| 129 | + <p><a href="http://www.w3.org/TR/css-grid-1/#auto-placement">Spec</a></p> |
| 130 | + </div> |
| 131 | + <table id="table"> |
| 132 | + <tr> |
| 133 | + <td></td> |
| 134 | + <td></td> |
| 135 | + <td></td> |
| 136 | + </tr> |
| 137 | + <tr> |
| 138 | + <td></td> |
| 139 | + <td></td> |
| 140 | + <td></td> |
| 141 | + </tr> |
| 142 | + <tr> |
| 143 | + <td></td> |
| 144 | + <td></td> |
| 145 | + <td></td> |
| 146 | + </tr> |
| 147 | + </table> |
| 148 | +</body> |
| 149 | +</html> |
0 commit comments