需要通过css将颜色添加到html表中

<?php
    $con=mysqli_connect("localhost","root","","db");
    // Check connection
    if (mysqli_connect_errno()) 
        {
            echo "Failed to connect to MySQL: " . mysqli_connect_error();
        }
        $co_name = mysqli_real_escape_string($con, $_POST['co_name']);
        $co_address = mysqli_real_escape_string($con, $_POST['co_address']);
        $co_website = mysqli_real_escape_string($con, $_POST['co_website']);
        $co_phoneno = mysqli_real_escape_string($con, $_POST['co_phoneno']);
        $co_contactperson = mysqli_real_escape_string($con, $_POST['co_contactperson']);
        $therapist_id = mysqli_real_escape_string($con, $_POST['therapist_id']);

        $result = mysqli_query($con,"SELECT * FROM therapist_office WHERE therapist_id='".$user_id."'");
        echo"<table id='miyazaki' style='border-collapse: collapse; border: 1px solid; margin-left:180px; width:1000px; margin-top:30px;'>";
            echo"<thead style='border:1px solid; background-color:#ffe3ab;' >";
                echo"<tr>";
                    echo"<th style='border: 1px solid; padding: .65em;' >Office Name</th>";
                    echo"<th style='border: 1px solid; padding: .65em;' >Address</th>";
                    echo"<th style='border: 1px solid; padding: .65em;' >Website</th>";
                    echo"<th style='border: 1px solid; padding: .65em;' >PhoneNo</th>";
                    echo"<th style='border: 1px solid; padding: .65em;'>Contact Person</th>";
                echo"</tr>";
            echo"</thead>";

            while($row = mysqli_fetch_array($result)) 
                {
                    echo"<tbody>";
                        echo"<tr>";
                            echo "<td style=' padding: .65em;'>" . $row['co_name'] . "</td>";
                            echo "<td style=' padding: .65em;'>" . $row['co_address'] . "</td>";
                            echo "<td style=' padding: .65em;'>" . $row['co_website'] . "</td>";
                            echo "<td style=' padding: .65em;'>" . $row['co_phoneno'] . "</td>";
                            echo "<td style=' padding: .65em;'>" . $row['co_contactperson'] . "</td>";
                        echo"</tr>";
                    echo"</tbody>";
                }   
        echo"</table>";
    mysqli_close($con);
?>

I have this table that is simple but i am not able to add colors through css to it, at present i have used inline css will convert it to external css later. i wish to show the table head with different color and the rows of the table that contain data should be of 2 colors that run alternatively. Would appreciate if someone could help me

P.S some people wanted to see my other sheet, here it is

<style>
        table { border-collapse: collapse; font-family: Futura, Arial, sans-serif; border: 1px solid ; margin-left:180px; width:1000px; margin-top:30px;}
        caption { font-size: larger; margin: 1em auto; }
        th, td { padding: .65em; }
        th, thead { background-color: ffecc4; border: 1px solid ; }
        tr:nth-child(odd) { background: #ccc; }
        tr:hover { background: #aaa; } 
        td { border-right: 1px solid #777; }         
    </style>

In html TABLE you cannot give background-color or color to <thead>. <thead> doesn't not take any colors. You can do..

#miyazaki thead th{
 background-color:red;
 color:#000;}

And for alternate colors you can apply

#miyazaki tr:nth-child(odd){ 
    background: #b8d1f3;
}

#miyazaki tr:nth-child(even){
    background: #dae5f4;
}

You can do it with CSS:

#miyazaki tr:nth-child(even) {background: #CCC}
#miyazaki tr:nth-child(odd) {background: #FFF}

Reference

Note: No support in IE 8 for this.

Or, if you have jQuery:

<script>
$(document).ready(function() {
  $("#miyazaki tr:even").css("background-color", "#CCC");
  $("#miyazaki tr:odd").css("background-color", "#FFF");
});
</script>

if you add classes to you code e.g

 `echo"<th style='border: 1px solid; padding: .65em;' class='tblHead'>Office Name</th>";`

and

 `echo "<td style=' padding: .65em;'>" . $row['co_name'] . " class='tblRow' </td>";`

Then you can write some CSS to set styles for those classes.

like:

 .tblHead {
    background-color: yellow;
 }

 .tblRow{
    background-color: green;
 }

Do it with jquery:

<script>
$(document).ready(function() {
  $("#miyazaki tr:even").css("background-color", "#CCC");
  $("#miyazaki tr:odd").css("background-color", "#FFF");
});
</script>