22 Aug 2015

How to style table using just HTML and CSS

First create a HTML file as given here:

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" href="css/primary.css">
    </head>
    <body>
        <table>
            <thead><tr><th>Name</th><th>Age</th></tr></thead>
            <tbody>
                <tr><td>Alex</td><td>22</td></tr>
                <tr class="odd"><td>Hales</td><td>23</td></tr>
                <tr><td>Strauss</td><td>42</td></tr>
                <tr class="odd"><td>Micheal</td><td>13</td></tr>
            </tbody>
        </table>
    </body>
</html>

Create a CSS file as given here:

table{
    border-collapse: collapse;
}
table thead tr th, table tbody tr td{
    border: 1px solid #000;
    padding: 3px;
}
table thead{
    background: #000;
    color: #fff;
}

table tr.odd{
    background: #ddd;
}



Share:

0 comments:

Post a Comment