Certo! Ecco un esempio di una scacchiera in HTML con una grafica moderna e accattivante, utilizzando HTML, CSS e un po' di JavaScript per renderla interattiva. Puoi copiare e incollare questo codice in un file .html e aprirlo nel browser:
🔲 Esempio di Scacchiera Moderna in HTML/CSS
📁 index.html
html Copy code
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Scacchiera Moderna</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="chessboard" id="chessboard"></div>
<script src="script.js"></script>
</body>
</html>
📁 style.css
css Copy code
body {
margin: 0;
padding: 0;
background: linear-gradient(135deg, #1e1e2f, #2c2c3c);
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
font-family: 'Segoe UI', sans-serif;
}
.chessboard {
display: grid;
grid-template-columns: repeat(8, 60px);
grid-template-rows: repeat(8, 60px);
box-shadow: 0 0 20px rgba(0,0,0,0.5);
border: 4px solid #444;
border-radius: 10px;
overflow: hidden;
}
.square {
width: 60px;
height: 60px;
display: flex;
justify-content: center;
align-items: center;
font-size: 32px;
transition: background 0.3s;
}
.square.light {
background-color: #f0d9b5;
}
.square.dark {
background-color: #b58863;
}
.square:hover {
background-color: #a3c9a8 !important;
cursor: pointer;
}
📁 script.js
javascript Copy code
const board = document.getElementById('chessboard');
const files = ['a','b','c','d','e','f','g','h'];
for (let row = 8; row >= 1; row--) {
for (let col = 0; col < 8; col++) {
const square = document.createElement('div');
square.classList.add('square');
const isLight = (row + col) % 2 === 0;
square.classList.add(isLight ? 'light' : 'dark');
// Optional: add coordinates as data attributes
square.dataset.coord = files[col] + row;
board.appendChild(square);
}
}
✨ Caratteristiche:
Design moderno con colori eleganti (marrone chiaro e scuro).
Effetto hover per rendere la scacchiera interattiva.
Responsive e centrata nella pagina.
Codice pulito e facilmente estendibile (puoi aggiungere pezzi, mosse, ecc.).
🧩 Prossimi passi (opzionali):
Aggiungere i pezzi degli scacchi (con emoji ♟, ♞, ♜ o immagini SVG).
Gestire le mosse con JavaScript.
Aggiungere coordinate visive (etichette a bordo scacchiera).
Fammi sapere se vuoi anche i pezzi o funzionalità aggiuntive! ♟️