繁体   English   中英

在回显php表上使用css

[英]using css on echo php table

下面是我的代码,该代码要求使用php创建一个表,它具有非常基本的样式。

<?php
    $result = mysql_query("SELECT * FROM League ORDER BY Points DESC, Difference DESC, TeamName DESC");
    echo "<style>#size{height:100px;width:340px;overflow-y:scroll;}</style>";
    echo "<table id='size' border='1'>;
            <tr>
            <th>Team</th>
            <th>Played</th>
            <th>Won</th>
            <th>Drawn</th>
            <th>Lost</th>
            <th>For</th>
            <th>Against</th>
            <th>Difference</th>
            <th>Bonus Pts</th>
            <th>Points</th>
            </tr>";

    while($row = mysql_fetch_array($result))
    {
        echo "<tr>";
        echo "<td>" . $row['TeamName'] . "</td>";
        echo "<td>" . $row['Played'] . "</td>";
        echo "<td>" . $row['W'] . "</td>";
        echo "<td>" . $row['L'] . "</td>";
        echo "<td>" . $row['D'] . "</td>";
        echo "<td>" . $row['PF'] . "</td>";
        echo "<td>" . $row['PA'] . "</td>";
        echo "<td>" . $row['Difference'] . "</td>";
        echo "<td>" . $row['BonusPoints'] . "</td>";
        echo "<td>" . $row['Points'] . "</td>";
        echo "</tr>";  
    }
    echo "</table>";
?>

我还创建了一种在我的CSS文件中设置其样式的方法,下面是代码

#customers
{
    font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
    width:100%;
    border-collapse:collapse;
}
#customers td, #customers th 
{
    font-size:1em;
    border:1px solid #98bf21;
    padding:3px 7px 2px 7px;
}
#customers th 
{
    font-size:1.1em;
    text-align:left;
    padding-top:5px;
    padding-bottom:4px;
    background-color:#A7C942;
    color:#ffffff;
}

我知道我的表没有使用该表的客户ID,但是当我这样做时将不起作用。 因此,我在顶部添加了简单的样式,以查看它是否有效。 有什么建议可以让我使用客户样式吗? 谢谢

当您声明样式时,只能在页面的头部声明。

当您在代码内部声明时,以这种方式使用样式。

<?php

echo "<table id='size' style='height:100px;width:340px;overflow-y:scroll;' border='1'>";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM