0

以下にcssファイルとhtmlファイルを追加しました。名前の色を変更してテーブルに色を付ける必要がありますが、うまくいきません。どこで間違いを犯したのかわかりません。

CSS ファイル :-

table.gridtable{
    font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
    float:center;
    border-width:1px;
    border-style:groove;
    border-color:black;
    border-collapse:collapse;
    width:600px;
    }
    table.gridtable th{
    border-width:1px;
    padding:3px;
    border-style:solid;
    border-color:black;
    }
    table.gridtable td{
    border-width:1px;
    padding:3px;
    border-style:solid;
    border-color:black;
    }
    .oddrowcolor{
    background-color: black;
    }
    .evenrowcolor{
    background-color: red;
    }
    table.gridtable td.darkcol{
    border-top:0px;
    border-bottom:0px;
    border-right: 1px;
    }
    table.gridtable td.emptycol{
    border-bottom:0px;
    border-right: 1px;
    }

HTML & PHP:-

 <table class="gridtable" id="alternatecolor" align="center"
 <tr><th>disease Name/th><th>Gene Name/th><th>OMIM Number</th></tr>  
 <?php
    $dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
    $selected = mysql_select_db("missensencemuttation",$dbhandle) or die("Could not select disease");
    $result = mysql_query("SELECT DISTINCT * FROM `gene_data` ORDER BY disease_name");
        $last=" ";
    while($row = mysql_fetch_array($result))    

        $now=$row[2];
        if($last != $now){
                $rcnt=mysql_query("select count(gene_name) from gene_data where gene_name='$now'");
        if($rcnt==1){
        echo "<tr><td>";   
        echo "<a href='d1.php?d_name=".$row['disease_name']."'>".$row['disease_name'];
        echo "</a></td>";       
        echo "<td>".$row['gene_name']."</td>";
        echo "<td>".$row['ommi_number']."</td></tr>";
        }
        else{
        echo "<tr><td class='emptycol'>";   
        echo "<a href='d1.php?d_name=".$row['disease_name']."'>".$row['disease_name'];
        echo "</a></td>";       
        echo "<td>".$row['gene_name']."</td>";
        echo "<td>".$row['ommi_number']."</td></tr>";
        }
        }
        else
        {
        echo "<tr'>";
        echo "<td class='darkcol'>";   
        echo '&nbsp';
        echo "</td>";       
        echo "<td>".$row['gene_name']."</td>";
        echo "<td>".$row['ommi_number']."</td></tr>";
        }
        $last=$row[2];      

誰でもこれで私を助けることができますか??

4

2 に答える 2

2

たぶん私は誤解していますが、行を交互に適用しoddrowcolorたりevenrowcolor、行を交互にしたいようです-しかし、実際のphp/htmlでは、これらのクラス名はどこにも表示されません。それらは行に配置されていないため、ルールは適用されません。<tr>それらをphpの適切なタグに追加するだけで機能します。nth-of-typeまたは、php を変更せずにセレクターを使用してルールを適用することもできます。

tr:nth-of-type(odd) {
    background-color: black;
}
tr:nth-of-type(even) {
    background-color: red;
}
于 2013-04-15T04:25:16.103 に答える
0

表の行ごとに別の色が必要な場合は、単純な CSS でそれを行う必要があります。このように、新しい行を動的に挿入する場合は、色が自動的に調整されます。

.stripped-rows:nth-child(odd){
   background-color:red;
 }
.stripped-rows:nth-child(even){
   background-color:blue;
 }

そしてhtml ...

 <table>
 <tr class = 'stripped-rows'>
     <td>sad</td>
 </tr>
 <tr class = 'stripped-rows'>
  <td>sad</td>
</tr>
 <tr class = 'stripped-rows'>
   <td>sad</td>
</tr>

デモ

于 2013-04-15T06:19:02.307 に答える