如何使用HTML::Table仅为数据行设置列类?
特雷 从perl数据结构中形成HTML表具有很好的灵活性,但我没有找到合适的方法来在同一列中使用与普通单元格(如何使用HTML::Table仅为数据行设置列类?,html,css,perl,Html,Css,Perl,特雷 从perl数据结构中形成HTML表具有很好的灵活性,但我没有找到合适的方法来在同一列中使用与普通单元格(td)不同的th-标记。或者让我换一种说法:如果我设置了column类,我只想为数据行设置它,而不是为标题行设置它 use strict; use warnings; use HTML::Table; my $table = new HTML::Table( -head=> ['one', 'two', 'eleven'],
td
)不同的th
-标记。或者让我换一种说法:如果我设置了column类,我只想为数据行设置它,而不是为标题行设置它
use strict;
use warnings;
use HTML::Table;
my $table = new HTML::Table(
-head=> ['one', 'two', 'eleven'],
-data=> [ ['yki', 'kaki', 'kommi'],
['yy', 'kaa', 'koo'] ]
);
$table->setColClass(1, 'class');
$table->setSectionColClass('tbody', 0, 2, 'class2');
print $table;
输出为:
<table>
<tbody>
<tr><th class="class">one</th><th class="class2">two</th><th>eleven</th></tr>
<tr><td class="class">yki</td><td class="class2">kaki</td><td>kommi</td></tr>
<tr><td class="class">yy</td><td class="class2">kaa</td><td>koo</td></tr>
</tbody>
</table>
内特韦勒文
伊基卡科米
雅库
我正在寻找的输出:
<table>
<tbody>
<tr><th>one</th><th>two</th><th>eleven</th></tr>
<tr><td class="class">yki</td><td class="class2">kaki</td><td>kommi</td></tr>
<tr><td class="class">yy</td><td class="class2">kaa</td><td>koo</td></tr>
</tbody>
</table>
内特韦勒文
伊基卡科米
雅库
有节级方法,但
th
也属于tbody
。表可能非常复杂,因此我希望避免重复标题行,并希望找到一种合适的方法。有吗?只需稍微调整一下CSS就可以了。您的样式表中大概有这样的内容:
.class { /* Some pretty stuff */ }
因此,只需更改选择器即可调整标题和正文单元格的样式:
td.class { /* The styles you want applied to body cells go here. */ }
th.class { /* And the styles for header cells (if any) go here. */ }
如果您不想对标题单元格应用任何样式,则在样式表中包含
td.class{}
位,并将th.class{}
保留在外;将CSS类附加到与样式表中的任何内容都不匹配的元素上没有什么错。我现在这样做了,但我想使用更优雅的解决方案。如果我不在th
上使用class属性,我也希望避免使用它。这就是为什么我没有将其标记为html或css;)实际上,我认为CSS方法是一个优雅的解决方案。但一个人的优雅解决方案是另一个人的黑客:)