HTML & CSS

Support de cours élaboré par : Youssef CHAFAI

Date : 18 mai 2025 | Version : 1.0

Exercices HTML – Section 4: Tableaux

Exercice 1 – Créer un tableau simple

Créez un tableau simple avec deux colonnes ("Fruit", "Couleur") et trois lignes de données.

<!-- Votre code ici -->
<!DOCTYPE html>
<html lang="fr">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Tableau Simple</title>
  <style>
    table { border-collapse: collapse; width: 50%; margin-top: 1em;}
    th, td { border: 1px solid #ccc; padding: 0.5em; text-align: left;}
    th { background-color: #f0f0f0; }
  </style>
</head>
<body>
  <table>
    <tr>
      <th>Fruit</th>
      <th>Couleur</th>
    </tr>
    <tr>
      <td>Pomme</td>
      <td>Rouge</td>
    </tr>
    <tr>
      <td>Banane</td>
      <td>Jaune</td>
    </tr>
    <tr>
      <td>Cerise</td>
      <td>Rouge</td>
    </tr>
  </table>
</body>
<html>

Exercice 2 – Tableau avec sections sémantiques

Reprenez le tableau de l'exercice 1 et ajoutez les balises <thead> et <tbody>.

<!-- Votre code ici -->
<!DOCTYPE html>
<html lang="fr">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Tableau Sémantique</title>
  <style>
    table { border-collapse: collapse; width: 50%; margin-top: 1em;}
    th, td { border: 1px solid #ccc; padding: 0.5em; text-align: left;}
    thead { background-color: #f0f0f0; }
  </style>
</head>
<body>
  <table>
    <thead>
      <tr>
        <th>Fruit</th>
        <th>Couleur</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>Pomme</td>
        <td>Rouge</td>
      </tr>
      <tr>
        <td>Banane</td>
        <td>Jaune</td>
      </tr>
      <tr>
        <td>Cerise</td>
        <td>Rouge</td>
      </tr>
    </tbody>
  <html>

Exercice 3 – Tableau avec fusion de cellules

Créez un tableau simple représentant un emploi du temps avec une cellule qui fusionne deux colonnes pour un cours qui dure deux heures.

<!-- Votre code ici -->
<!DOCTYPE html>
<html lang="fr">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Tableau avec Fusion</title>
  <style>
    table { border-collapse: collapse; width: 80%; margin-top: 1em;}
    th, td { border: 1px solid #ccc; padding: 0.5em; text-align: center;}
    th { background-color: #f0f0f0; }
  </style>
</head>
<body>
  <table>
    <thead>
      <tr>
        <th>Heure</th>
        <th>Lundi</th>
        <th>Mardi</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>9h-10h</td>
        <td>HTML</td>
        <td>CSS</td>
      </tr>
      <tr>
        <td>10h-12h</td>
        <td colspan="2">Projet</td>
      </tr>
    </tbody>
  </table>
</body>
<html>
↑ Sommaire