Zebra-striping nested lists with CSS

为君一笑 提交于 2019-12-06 09:21:54
SpliFF

Short answer, no. Long answer, yes, by targeting the nested items, eg:

li:nth-child(odd) {background:blue}
li:nth-child(odd) li:nth-child(even) {background:blue}
li:nth-child(even) li:nth-child(odd) {background:blue}

But beyond 2 or three levels you're probably going to need a lot of rules.

You could do it with javascript as well, by walking down the tree and incrementing a counter, applying the style when the counter is odd or even.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!