JSFiddle - React, Tailwind, and code Playground
by coryphoenixxx
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="style.css" />
<link rel="stylesheet" href="normalize.css">
<title>Pixel Art</title>
</head>
<body>
<div id="container">
<div id="canvas">
</div>
<div id="color_panel"></div>
</div>
<script src="script.js"></script>
</body>
</html>
CSS
body {
display: flex;
justify-content: center;
align-items: center;
padding-top: 50px;
}
#container {
width: 1000px;
height: 600px;
background: lightgray;
border-radius: 10px;
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}
#canvas {
display: flex;
justify-content: center;
align-items: center;
flex-flow: column;
flex-wrap: wrap;
/* gap: 1px; */
padding: 20px;
}
.pixel {
margin: 1px;
width: 8px;
height: 8px;
background: white;
}
.row {
display: inline-flex;
justify-content: center;
align-items: center;
flex-flow: row;
flex-wrap: wrap;
gap: 1px;
}
JavaScript
function create_canvas(width, height) {
for (let j=0; j < height; j++) {
let row = document.createElement('div');
row.classList.add('row')
canvas.appendChild(row)
for (let i=0; i < width; i++) {
let pixel = document.createElement('div');
pixel.classList.add('pixel')
row.appendChild(pixel)
}
}
}
create_canvas(20, 1)