简体   繁体   English

更改备用行的颜色

[英]Changing colour for alternate rows

I want to make a table more readable by alternating row colours. 我想通过交替的行颜色使表格更具可读性。 I've been through the other answers but can't see how to apply them to my code. 我已经看完其他答案,但是看不到如何将它们应用于我的代码。 I tried various toggle methods in the last bit of the code but just broke everything. 我在代码的最后一部分尝试了各种切换方法,但一切都中断了。

I can't use jquery or CSS because I can only access this part of the code. 我不能使用jquery或CSS,因为我只能访问这部分代码。

I want to toglle to bgcolor="#8BC6FD" 我想切换到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>

I can't use jquery or CSS because I can only access this part of the code. 我不能使用jquery或CSS,因为我只能访问这部分代码。

It's unclear as to which part of code you're referring. 目前尚不清楚您指的是代码的哪一部分。 Assuming you can access all the code showed, you can place the <style> tag before or after the <table> . 假设您可以访问显示的所有代码,则可以将<style>标记放在<table>之前或之后。

It's as simple as defining n-th CSS like 就像定义第n个CSS一样简单

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

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

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