HTML Table Styling

0
11χλμ.

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
Αναζήτηση
Κατηγορίες
Διαβάζω περισσότερα
Computer Programming
Functions, Finally, and Custom Exceptions
These three concepts are essential for writing robust and maintainable Python code. Here's a...
από Python for Everybody - Full University Python Course Code 2024-07-19 05:16:31 0 11χλμ.
Business
How to Start Selling on Amazon FBA: A Step-by-Step Guide
Are you looking to tap into the booming world of e-commerce? Selling on Amazon using Fulfillment...
από Mpatswe Francis 2024-09-18 20:21:05 0 9χλμ.
Biology
CAPILLARITY
How does capillary action work in plants? Capillary action in plants works through the...
από Okiliong Peter 2024-09-04 13:04:49 0 18χλμ.
Computer Programming
Setting up a text editor for HTML
Choosing a Text Editor The first step is to select a suitable text editor. There are numerous...
από HTML PROGRAMMING LANGUAGE 2024-08-13 03:18:39 0 8χλμ.
Computer Programming
Branching Basics and Multi-Branch Statements in Python
Branching is a fundamental concept in programming that allows your code to make decisions and...
από Python for Everybody - Full University Python Course Code 2024-07-16 21:42:09 0 9χλμ.
Tebtalks https://forum.tebtalks.com