具有内联样式CSS的表上的备用行颜色 [英] Alternate Row Colours on Tables with Inline Style CSS

查看:146
本文介绍了具有内联样式CSS的表上的备用行颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想改变表格的背景颜色以提高可读性.谷歌搜索了一下之后,我找到了所需的代码.

I want to alternate the background colour of a table to increase readability. After googling a bit I found the code I needed.

tr:nth-child(even) {
    background-color: #000000;
}

解决方案中的问题,我无权访问head标记,并且我想使用内联样式CSS来实现此功能,但这不起作用.

The problem in my solution, I don't have access to head tag, and I want to implement this with inline style CSS, but it doesnt work.

<tr style="nth-child(even) background-color: #000000;">

想法?

推荐答案

内联样式是逐元素的,因此您必须将适当的样式插入到每个其他tr元素的style属性中.如果尚未动态生成这些行,并且无法使用JavaScript注入这些样式,那么您就不得不在每个tr元素上手动应用该属性.

Inline styles are per-element, so you would have to inject the appropriate styles into the style attribute of every other tr element. If you're not already generating these rows dynamically, and you cannot use JavaScript to inject these styles, then you're stuck with having to manually apply the attribute on each tr element.

这篇关于具有内联样式CSS的表上的备用行颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆