HTML Table Styling

0
3χλμ.

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
Αναζήτηση
Κατηγορίες
Διαβάζω περισσότερα
Chemistry
UCE CHEMISTRY JJEB 2024
UCE CHEMISTRY JJEB 2024
από Landus Mumbere Expedito 2024-08-12 09:34:13 0 4χλμ.
Εκπαίδευση
S.4 PHYSICAL EDUCATION MOCK EXAM
https://acrobat.adobe.com/id/urn:aaid:sc:EU:ec617028-2a6c-4082-b406-54df86b57b55
από Landus Mumbere Expedito 2024-07-24 19:32:08 0 3χλμ.
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 3χλμ.
Business
Business Success is a Marathon, Not a Sprint
Strategies for Thriving in Today’s Fast-Paced Environment In the fast-paced world of...
από ALAGAI AUGUSTEN 2024-08-03 15:39:53 0 3χλμ.
Εκπαίδευση
A MUST KNOW FOR S6 HISTORY STUDENTS
https://acrobat.adobe.com/id/urn:aaid:sc:EU:8ec647ff-c6ae-4844-831f-3f6e719e9bb0
από Landus Mumbere Expedito 2024-07-15 19:59:30 0 4χλμ.