Sunday, June 12, 2022

Table using HTML and CSS

Step 1: Create a file Table.html with the following content.

<!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"/>

    <link rel="preconnect" href="https://fonts.googleapis.com" />
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin/>
    <link
      href="https://fonts.googleapis.com/css2?
      family=Inter:wght@400;500;700&display=swap"
      rel="stylesheet"
    />

    <title>Table Component</title>
    <style>
      * {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
      }

      body {
        font-family: "Inter", sans-serif;
        color: #343a40;
        line-height: 1;
        display: flex;
        justify-content: center;
      }

      table {
        width: 800px;
        margin-top: 60px;
        font-size: 18px;
        /* border: 1px solid #343a40;*/
        border-collapse: collapse;
      }

      th,
      td {
        /* border: 1px solid #343a40; */
        padding: 16px 24px;
        text-align: left;
      }

      thead tr {
        background-color: #4c6ef5;
        color: #fff;
      }

      thead th {
        width: 25%;
      }

      tbody tr:nth-child(odd) {
        background-color: #f8f9fa;
      }

      tbody tr:nth-child(even) {
        background-color: #e9ecef;
      }
    </style>
  </head>
  <body>
    <table>
      <thead>
        <tr>
          <th>Image</th>
          <th>Name</th>
          <th>Office</th>
          <th>Age</th>
        </tr>
      </thead>

      <tbody>
        <tr>
          <td><img src="./Leonardo.png" /></td>
          <td>Leonardo</td>
          <td>San Francisco</td>
          <td>33</td>
        </tr>

        <tr>
          <td><img src="./Leonardo.png" /></td>
          <td>Brad Pitt</td>
          <td>London</td>
          <td>35</td>
        </tr>

        <tr>
          <td><img src="./Leonardo.png" /></td>
          <td>Anjolina</td>
          <td>New York</td>
          <td>34</td>
        </tr>

        <tr>
          <td><img src="./Leonardo.png" /></td>
          <td>Paul Walker</td>
          <td>Tokyo</td>
          <td>38</td>
        </tr>
      </tbody>
    </table>
  </body>
</html>

Result:



 

No comments:

Post a Comment