-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathSimple Grid Layout Generator
More file actions
45 lines (45 loc) · 1.32 KB
/
Simple Grid Layout Generator
File metadata and controls
45 lines (45 loc) · 1.32 KB
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
<!-- Objective: Create a tool to generate a simple grid layout based on user inputs for rows and columns. -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Grid Layout Generator</title>
<style>
#gridContainer {
display: grid;
gap: 10px;
padding: 10px;
}
.grid-item {
background-color: #bada55;
padding: 20px;
text-align: center;
color: white;
}
</style>
</head>
<body>
<label for="rows">Rows:</label>
<input type="number" id="rows" min="1" value="2">
<label for="columns">Columns:</label>
<input type="number" id="columns" min="1" value="2">
<button id="generate">Generate Grid</button>
<div id="gridContainer"></div>
<script>
document.getElementById('generate').addEventListener('click', function() {
const rows = document.getElementById('rows').value;
const columns = document.getElementById('columns').value;
const gridContainer = document.getElementById('gridContainer');
gridContainer.style.gridTemplateRows = `repeat(${rows}, 1fr)`;
gridContainer.style.gridTemplateColumns = `repeat(${columns}, 1fr)`;
gridContainer.innerHTML = ''; // Clear previous grid items
for (let i = 0; i < rows * columns; i++) {
const gridItem = document.createElement('div');
gridItem.textContent = `Item ${i + 1}`;
gridItem.className = 'grid-item';
gridContainer.appendChild(gridItem);
}
});
</script>
</body>
</html>