HTML Table Styling

0
3K

HTML Table Styling

You can use CSS to style HTML tables and their elements, providing greater flexibility and customization options. Here are some common styling techniques:

Table-Level Styling

  • Border:
    CSS
    table {
      border: 1px solid #ccc;
    }
    
  • Width:
    CSS
    table {
      width: 80%;
    }
    
  • Background Color:
    CSS
    table {
      background-color: #f2f2f2;
    }
    

Header and Data Cell Styling

  • Font:
    CSS
    th {
      font-weight: bold;
      text-align: center;
    }
    
    td {
      text-align: left;
    }
    
  • Background Color:
    CSS
    th {
      background-color: #4CAF50;
      color: white;
    }
    
  • Padding:
    CSS
    th, td {
      padding: 8px;
    }
    

Striped Rows

CSS
tr:nth-child(even) {
  background-color: #f2f2f2;
}

Hover Effects

CSS
tr:hover {
  background-color: #ddd;
}

Example

HTML
<table style="border: 1px solid #ccc; width: 80%;">
  <thead>
    <tr>
      <th style="background-color: #4CAF50; color: white;">Product</th>
      <th style="background-color: #4CAF50; color: white;">Price</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Product A</td>
      <td>$100</td>
    </tr>
    <tr style="background-color: #f2f2f2;">
      <td>Product B</td>
      <td>$200</td>
    </tr>
  </tbody>
</table>

Note: For more advanced styling, consider using CSS frameworks like Bootstrap or Materialize, which provide pre-built styles and components for tables and other elements.

By combining these techniques, you can create visually appealing and informative HTML tables that enhance the user experience of your web applications.

Like
2
Search
Categories
Read More
Technology
Computer Netwrks
A computer network is a collection of interconnected devices that share resources and...
By Mpatswe Francis 2024-10-03 23:03:52 0 3K
Computer Programming
Floating-Point Numbers and Arithmetic Expressions
Floating-point numbers A floating-point number is a number with a decimal. Ex: 3.14,...
Computer Programming
Quotations (<blockquote>, <q>)
Quotes are used to display text that is a direct quote from another source. In HTML, there are...
By HTML PROGRAMMING LANGUAGE 2024-08-29 02:08:24 0 3K
Education
S.4 CRE PRE-REGISTRATION 2024
https://acrobat.adobe.com/id/urn:aaid:sc:EU:21663e65-af20-41e8-b997-5def68c7399f
By Landus Mumbere Expedito 2024-07-19 23:19:32 0 3K