[mysql]需要把颜色放到一个 html 表,通过 css

标签: html5 MySQL PHP HTML CSS
发布时间: 2016/10/16 10:40:29
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.
<?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);
?>

我有此表的简单但我不能够添加通过 css,目前我已经使用内联 css 颜色将其转换为外部 css 后。希望能够呈现不同颜色的表头和表包含数据的行应该是 2 种颜色,或者运行。如果有人能帮我将不胜感激

另外一些人想看看我的其他工作表,它在这儿

<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>

解决方法 1:

在 html 表中你不能给背景颜色或颜色 <thead> . <thead> 不需要任何颜色。你可以做...

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

对于备用颜色可以应用

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

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