Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何为HTML表格创建斑马样式的CSS?_Php_Html_Css - Fatal编程技术网

Php 如何为HTML表格创建斑马样式的CSS?

Php 如何为HTML表格创建斑马样式的CSS?,php,html,css,Php,Html,Css,我想在我的PHP表上为每一行创建一个斑马样式。现在,使用上面的CSS代码: table.imagetable td:nth-child(odd) { background-color:#ccc; } 我有斑马风格,但只对每一列这是不可取的。有没有办法解决这个问题 您需要在偶数行中放置类似的内容 table.imagetable tr:nth-child(even) { background-color:#fff; } 如下所示,您可以使用第n个类型选择器: /* Changes

我想在我的PHP表上为每一行创建一个斑马样式。现在,使用上面的CSS代码:

table.imagetable td:nth-child(odd) 
{
  background-color:#ccc;
}

我有斑马风格,但只对每一列这是不可取的。有没有办法解决这个问题

您需要在偶数行中放置类似的内容

table.imagetable tr:nth-child(even) 
{
  background-color:#fff;
}

如下所示,您可以使用第n个类型选择器:

/* Changes the background color of every odd row to light gray */
table tr:nth-of-type(odd) {
  background-color: #ccc;
}

/* Changes the weight of each td cell within each odd row to bold */
table tr:nth-of-type(odd) td {
  font-weight: bold;
}

/* Collapses table borders to make the table appear continuous */
table {
  border-collapse: collapse;
}

/* Spaces out each table cell */
table td {
  padding: 1em;
}
/*将每个奇数行的背景色更改为浅灰色*/
表tr:第n种类型(奇数){
背景色:#ccc;
}
/*将每个奇数行中每个td单元格的权重更改为粗体*/
表tr:nth型(奇数)td{
字体大小:粗体;
}
/*折叠表格边框以使表格显示为连续*/
桌子{
边界塌陷:塌陷;
}
/*将每个表单元格隔开*/
表td{
填充:1em;
}

第1单元
第2单元
第三单元
第1单元
第2单元
第三单元
第1单元
第2单元
第三单元
第1单元
第2单元
第三单元
第1单元
第2单元
第三单元
第1单元
第2单元
第三单元

您必须在表格行上写入:

<tr class="<?=($c++%2==1) ? 'odd' : 'even' ?>" style="border:1">

为什么不用tr代替td?我已经试过了。但它不起作用。你也可以做两个css类,并在每一行上交替。同样出于好奇,你使用哪种浏览器?目前,我使用ChromeEyes,但这只适用于每一列,而不是每一列row@ather0s你在编辑我的答案时有进步吗?如果你解决了你的问题,别忘了检查,你能用你的html表格编辑你的帖子吗?如果可能的话,一个图像显示你想要什么
<style type="text/css">
.even { background-color:#FFFFFF } 
.odd { background-color:#EAEAEA }
</style>