用于交替行颜色的 CSS 条件语句(从最后一行开始?)
小装饰问题.. 我正在开发一个基于论坛的网站,其中包含包含页眉和页脚的动态 PHP 表格。我目前有一个 CSS 条件语句,用于交替表格中偶数行和奇数行的背景颜色。
<!-- IF forumrow.S_ROW_COUNT is even-->
<li class="row" style="background-color:#536482;">
<!-- ELSE -->
<li class="row" style="background-color:#E0EBB2;">
<!-- ENDIF -->
我的问题是,表格的通用页脚与条件语句中的偶数计数颜色相同,看起来有点奇怪,就像如果页脚与实际页脚颜色相同,它会让页脚看起来比实际更大。最后一行,即表格以偶数行结束。
我的问题是是否可以在条件语句中添加任何内容以使其从表的最后一行开始?那么页脚的最后一行将始终是#E0EBB2。
提前致谢。
Minor cosmetic issue.. I am in the process of developing a forum based site with dynamic PHP tables that include headers and footers. I currently have a CSS conditional statement for alternating background colors for even and odd rows in my tables.
<!-- IF forumrow.S_ROW_COUNT is even-->
<li class="row" style="background-color:#536482;">
<!-- ELSE -->
<li class="row" style="background-color:#E0EBB2;">
<!-- ENDIF -->
My issue is that the common footer of my tables are the same color as the even count in my conditional statement and it would look kind of weird, like it would make the footer look larger than it actually is if it were the same color as the last row, that is if the table were to end on an even numbered row.
My question is if there is anything I can add to my conditional statement to make it start at the last row of my tables? Then the last row against the footer would always be #E0EBB2.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以只使用 css 伪选择器
nth-last-child
,仅此而已。尝试一下:
工作示例此处。
You can use just the css pseudo selector
nth-last-child
and nothing more.Try it:
Working example here.
让 PHP 生成样式可能比依赖注释条件更好。在 PHP 脚本中,您还可以对行进行计数,如果是偶数则从某种颜色开始,如果是奇数则从另一种颜色开始。注释条件没有得到广泛或一致的支持。
It might be better to let PHP generate the styling than relying on comment conditionals. From the PHP script, you could also count the rows and start with a certain colour if even, the other one if odd. Comment conditionals are not widely or consistently supported.