Lädt...

🔧 Day 4: Creating Tables in HTML


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

Welcome to Day 4 of your journey to mastering HTML and CSS! Today, we will explore how to create and style tables in HTML. Tables are useful for displaying data in a structured format. By the end of this post, you'll be able to create and style tables for your web pages.

please subscribe to my YouTube channel to support my channel and get more web development tutorials.

An HTML table is defined with the <table> tag. Each row is defined with the <tr> (table row) tag, and each cell is defined with the <td> (table data) tag. Table headers are defined with the <th> (table header) tag.

Here's a simple example of an HTML table:

<table>
    <tr>
        <th>Header 1</th>
        <th>Header 2</th>
        <th>Header 3</th>
    </tr>
    <tr>
        <td>Data 1</td>
        <td>Data 2</td>
        <td>Data 3</td>
    </tr>
    <tr>
        <td>Data 4</td>
        <td>Data 5</td>
        <td>Data 6</td>
    </tr>
</table>

Adding Borders

To add borders to your table, you can use the border attribute directly in the <table> tag:

<table border="1">
    <tr>
        <th>Header 1</th>
        <th>Header 2</th>
        <th>Header 3</th>
    </tr>
    <tr>
        <td>Data 1</td>
        <td>Data 2</td>
        <td>Data 3</td>
    </tr>
    <tr>
        <td>Data 4</td>
        <td>Data 5</td>
        <td>Data 6</td>
    </tr>
</table>

Spanning Columns and Rows

You can span columns using the colspan attribute and rows using the rowspan attribute.

<table border="1">
    <tr>
        <th colspan="2">Header 1 & 2</th>
        <th>Header 3</th>
    </tr>
    <tr>
        <td rowspan="2">Data 1 & 4</td>
        <td>Data 2</td>
        <td>Data 3</td>
    </tr>
    <tr>
        <td>Data 5</td>
        <td>Data 6</td>
    </tr>
</table>

Styling Tables with CSS

To style tables, you can use CSS. Here are some common CSS properties for tables:

  1. Table Borders:
   table, th, td {
       border: 1px solid black;
       border-collapse: collapse;
   }
  1. Padding and Text Alignment:
   th, td {
       padding: 10px;
       text-align: left;
   }
  1. Table Width and Background Color:
   table {
       width: 100%;
       background-color: #f2f2f2;
   }
  1. Striped Rows:
   tr:nth-child(even) {
       background-color: #f2f2f2;
   }

Here's a complete example with CSS styling:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Styled Table</title>
    <style>
        table, th, td {
            border: 1px solid black;
            border-collapse: collapse;
        }
        th, td {
            padding: 10px;
            text-align: left;
        }
        table {
            width: 100%;
            background-color: #f2f2f2;
        }
        tr:nth-child(even) {
            background-color: #e6e6e6;
        }
    </style>
</head>
<body>
    <h1>HTML Table with CSS Styling</h1>
    <table>
        <tr>
            <th>Header 1</th>
            <th>Header 2</th>
            <th>Header 3</th>
        </tr>
        <tr>
            <td>Data 1</td>
            <td>Data 2</td>
            <td>Data 3</td>
        </tr>
        <tr>
            <td>Data 4</td>
            <td>Data 5</td>
            <td>Data 6</td>
        </tr>
    </table>
</body>
</html>

Summary

In this blog post, we explored how to create and style tables in HTML. We learned about basic table structure, adding borders, spanning columns and rows, and styling tables with CSS. Practice creating and styling tables to organize your data effectively.

Stay tuned for Day 5, where we will cover forms and their uses in HTML. Happy coding!

Follow me for more tutorials and tips on web development. Feel free to leave comments or questions below!

Follow and Subscribe:

...

🔧 HTML Tables: how to create and style tables with HTML


📈 36.11 Punkte
🔧 Programmierung

🔧 How to Apply Sorting on Tables in HTML Using JavaScript: Sortable Paginated Tables


📈 31.62 Punkte
🔧 Programmierung

🔧 Day 4: Creating Tables in HTML


📈 30.31 Punkte
🔧 Programmierung

🔧 Using Mapping Tables to Merge Data with Auto-Number Keys Referenced by Other Tables


📈 27.13 Punkte
🔧 Programmierung

📰 Storytelling with Tables Part 1: Tables with Plotly


📈 27.13 Punkte
🔧 AI Nachrichten

🕵️ Low CVE-2015-9401: Websimon-tables project Websimon-tables


📈 27.13 Punkte
🕵️ Sicherheitslücken

🕵️ Medium CVE-2017-18597: Jtrt responsive tables project Jtrt responsive tables


📈 27.13 Punkte
🕵️ Sicherheitslücken

📰 Microsoft Excel Can Now Turn Pictures of Tables Into Actual, Editable Tables


📈 27.13 Punkte
📰 IT Security Nachrichten

🔧 Creating your first catalog, schema and tables in DataBricks


📈 21.64 Punkte
🔧 Programmierung

📰 Creating Dynamic Pivots on Snowflake Tables with dbt


📈 21.64 Punkte
🔧 AI Nachrichten

🔧 Bootstrap: Creating Responsive Tables


📈 21.64 Punkte
🔧 Programmierung

🔧 18 Key Points You Must Know When Creating Tables in MySQL


📈 21.64 Punkte
🔧 Programmierung

🔧 Creating Secure Backups for DynamoDB Tables with Terraform


📈 21.64 Punkte
🔧 Programmierung

📰 Get started with SQLite3 in Python Creating Tables &amp; Fetching Rows


📈 21.64 Punkte
🔧 AI Nachrichten

📰 Virtuailor - IDAPython Tool For Creating Automatic C++ Virtual Tables In IDA Pro


📈 21.64 Punkte
📰 IT Security Nachrichten

🔧 How to Create Tables Using HTML


📈 18.05 Punkte
🔧 Programmierung

🔧 Automate HTML Tables Generation in PHP with this Modern Library


📈 18.05 Punkte
🔧 Programmierung

🔧 HTML &amp; CSS Tutorial for Beginners - Lists, Tables, Forms, Advanced CSS Selectors | Web Design


📈 18.05 Punkte
🔧 Programmierung

🔧 HTML Tables Tutorial with Examples: Become An Expert In 15 Minutes


📈 18.05 Punkte
🔧 Programmierung

🔧 Understand Tables: HTML in 180 Seconds - Episode 5


📈 18.05 Punkte
🔧 Programmierung

🔧 Getting Started with HTML Tables


📈 18.05 Punkte
🔧 Programmierung

🐧 How to Use Pagination on HTML Tables Using JavaScript


📈 18.05 Punkte
🐧 Linux Tipps

🔧 Day 22: How the Tables have turned 🏓


📈 17.74 Punkte
🔧 Programmierung

🔧 Day 5: Creating Forms in HTML


📈 16.74 Punkte
🔧 Programmierung

🔧 Day 2: Creating NBA Game Day Notification System using Event-Driven Architecture


📈 16.43 Punkte
🔧 Programmierung

🔧 Creating a To-Do app with Django and HTMX - Part 1: Creating the Django project with uv


📈 16.15 Punkte
🔧 Programmierung

🔧 Why in Typescript creating an enum doesn't need a =, but creating a new type does?


📈 16.15 Punkte
🔧 Programmierung

🔧 Creating Self-Serve DevOps Without Creating More Toil


📈 16.15 Punkte
🔧 Programmierung