Détail de l'article

Retour à la liste de la page d'accueil Update  Delete

Echiquier

Le damier d'un échiquier en JavaScript.

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Echiquier</title>
        <style>
            body {
                margin: 0;
            }
            main {
                width: 100vw;
                height: 100vh;
                display: grid;
                place-items: center;
            }
            .damier {
                width: 80vw;
                margin: auto;
                aspect-ratio: 1/1;
                background-color: rgb(200, 200, 200);
                display: grid;
                place-items: center;
            }
            table {
                background-color: white;
                width: 90%;
                aspect-ratio: 1/1;
            }
            tr:nth-child(even) td:nth-child(even) {
                background-color: black;
            }
            tr:nth-child(odd) td:nth-child(odd) {
                background-color: black;
            }
            @media (orientation: landscape) {
                .damier {
                    width: 80vh;
                }
            }
            @media (orientation: portrait) {
                .damier {
                    width: 80vw;
                }
            }
        </style>
    </head>
    <body>
        <main>
            <section class="damier">
                <script>
                    let lignes = 8;
                    let colonnes = 8;
                    document.write("<table>");
                    for (let y = 0; y < lignes; y++) {
                        // CREER LIGNES
                        document.write("<tr>");
                        for (let x = 0; x < colonnes; x++) {
                            document.write("<td></td>");
                        }
                        document.write("</tr>");
                    }
                </script>
            </section>
        </main>
    </body>
</html>

Détail de l'article