dongzhuo7291 2015-03-28 02:52 采纳率: 100%
浏览 24
已采纳

交替颜色HTML表PHP

I am trying to get my table to alternate colors but I am having some difficulty.

 if ($i % 2 == 0)
    $color = "grey";
    else
    $color = "white"; $i++;
    $table .= "<tr style=backround-color=$color>"; 

This does not work. I have tried this as well but it did not work either.

$table .= "<tr:nth-child(even) {background: #CCC};  tr:nth-child(odd) {background: #FFF}; >"; 
  • 写回答

2条回答 默认 最新

  • du0923 2015-03-28 02:59
    关注

    You misspelled background and you don't use = in CSS, you use :. I also added quotes around your attribute values as it is best practice:

    $table .= "<tr style='background-color:$color'>";
    

    The last line in your question isn't even close to valid HTML or CSS. Looks kinda neat though.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 安装华大九天aether
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证