Maison  >  Article  >  interface Web  >  Comment créer un tableau avec des en-têtes ?

Comment créer un tableau avec des en-têtes ?

WBOY
WBOYavant
2023-08-24 22:49:031373parcourir

Comment créer un tableau avec des en-têtes ?

Nous utilisons la balise

pour créer un tableau avec un titre en HTML. La balise title sera insérée après la balise Nous pouvons ajouter un titre à un tableau. Par défaut, l'alignement de l'étiquette est centré. Nous pouvons modifier l'alignement en utilisant la propriété CSS align.

Grammaire

Voici la syntaxe de la balise de titre HTML

<caption>Caption of the table...</caption>

Exemple 1

Dans l'exemple ci-dessous, nous avons créé un tableau contenant les noms et identifiants des employés en utilisant Employés comme titre.

<!DOCTYPE html>
<html>
<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">
   <style>
      table,
         tr,
         th,
         td {
            border: 1px solid black;
         }
   </style>
</head>
<body>
   <table>
      <caption>Employees</caption>
      <tr>
         <th>EmployeeName</th>
         <th>EmployeeId</th>
      </tr>
      <tr>
         <td>Yadav</td>
         <td>022</td>
      </tr>
      <tr>
         <td>Abdul</td>
         <td>025</td>
      </tr>
      <tr>
         <td>Jason</td>
         <td>208</td>
      </tr>
   </table>
</body>
</html>

Propriétés d'alignement

Nous pouvons utiliser l'attribut CSS align pour modifier l'alignement. Voici sa syntaxe :

<caption style="text-align:value" >Caption of the table...</caption>

Exemple 2

se traduit par :

Exemple 2

Dans l'exemple ci-dessous, nous alignons le titre sur le côté gauche de la page -

<!DOCTYPE html>
<html>
<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">
   <style>
      table,tr,th,td {
         border:1px solid black;
      }
   </style>
</head>
<body>
   <table>
      <caption style="text-align: left">Employees</caption>
      <tr>
         <th>EmployeeName</th>
         <th>EmployeeId</th>
      </tr>
      <tr>
         <td>Yadav</td>
         <td>022</td>
      </tr>
      <tr>
         <td>Abdul</td>
         <td>025</td>
      </tr>
      <tr>
         <td>Jason</td>
         <td>208</td>
      </tr>
   </table>
</body>
</html>

La traduction chinoise de

Exemple 3

est :

Exemple 3

Regardons un autre exemple de création d'un titre -

<!DOCTYPE html>
<html>
<head>
   <style>
      table,
      td,
      th {
         border: 1px solid black;
      }
   </style>
</head>
<body>
   <table>
      <caption>Authors</caption>
      <tr>
         <th>JavaFX</th>
         <th>Krishna</th>
      </tr>
      <tr>
         <td>Scala</td>
         <td>Satish</td>
      </tr>
   </table>
</body>
</html>

Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!

Déclaration:
Cet article est reproduit dans:. en cas de violation, veuillez contacter admin@php.cn Supprimer