dongziche8030 2014-12-03 06:00
浏览 33
已采纳

需要通过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>
  • 写回答

4条回答 默认 最新

  • doulin2025 2014-12-03 06:30
    关注

    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;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制