【问题标题】:Changing colour for alternate rows更改交替行的颜色
【发布时间】:2019-03-28 06:59:39
【问题描述】:

我想通过交替行颜色使表格更具可读性。我已经完成了其他答案,但看不到如何将它们应用到我的代码中。我在代码的最后一点尝试了各种切换方法,但只是破坏了一切。

我不能使用 jquery 或 CSS,因为我只能访问这部分代码。

我想切换到 bgcolor="#8BC6FD"

<table cellspacing=0 cellpadding=2 border="thin">
<col width=150>
<col width=100>

    <tr bgcolor="#D4E9FC" style="outline: thin solid">
    <td class="viewN"><b>TYPE:- </b></td>
    <td class="viewN"><b>PACKING:- </b></td>
    </tr>

    <?php 
    $dbconn = pg_connect("host=127.0.0.1 XXXX password=YYYY)") or die('Could not connect: ' . pg_last_error());

    $query = "SELECT * FROM stock
        ORDER BY name" ; 

    $result = pg_query($query); 
    if (!$result) { 
        echo "Problem with query " . $query . "<br/>"; 
        echo pg_last_error(); 
        exit(); 
    } 

    while($myrow = pg_fetch_assoc($result)) { 
        printf ("<tr><td>%s</td><td>%s</td></tr>", htmlspecialchars($myrow['type']),htmlspecialchars($myrow['packing']));
    } 
    ?> 
    </table>

【问题讨论】:

    标签: php html-table


    【解决方案1】:

    我不能使用 jquery 或 CSS,因为我只能访问这部分代码。

    目前尚不清楚您指的是代码的哪一部分。假设您可以访问显示的所有代码,您可以将&lt;style&gt; 标签放在&lt;table&gt; 之前或之后。

    就像定义第 n 个 CSS 一样简单

    <style>
        /* tr:nth-child(odd) {background-color: #0000cc} */
        tr:nth-child(even) {background-color: #D4E9FC}
    </style>
    

    【讨论】:

    • 你可以在表格之前或之后放置一个
    • 哦,太好了,已经折腾好几年了
    猜你喜欢
    • 1970-01-01
    • 2013-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多