Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Create your online store today with Shopify

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Disclosure: My content contains affiliate links.

43,404 questions

56,387 answers

573 users

How to set different colors to HTML table header and rows in CSS

1 Answer

0 votes
<!DOCTYPE html>
<html>
    <head>
        <style>
            table, th, td {
                border: 1px solid lightcoral;
                border-collapse: collapse;
                width: 20%;
            }
            #table_id tr:nth-child(even) {
                background-color: lightgray;
            }
            #table_id tr:nth-child(odd) {
                background-color: white;
            }
            #table_id th {
                background-color: black;
                color: white;
            }
        </style>
    </head>
    <body>

        <table id="table_id">
            <tr>
                <th>Name</th>
                <th>Language</th>
            </tr>
            <tr>
                <td>Fox</td>
                <td>PHP</td>
            </tr>
            <tr>
                <td>Angelina</td>
                <td>JavaScript</td>
            </tr>
            <tr>
                <td>Borat</td>
                <td>HTML</td>
            </tr>
            <tr>
                <td>Mr. Bean</td>
                <td>CSS</td>
            </tr>
        </table>

    </body>
</html>

 



answered Dec 13, 2018 by avibootz
...