I am building a website with PHP and MySQL which contains articles, and each of those articles can contain comments (rather like a typical blog). Each article page is like this
<?php
$blog_id = "1";
include("../includes/blog.php");
?>
and all the code is in blog.php.
The intention is that the comments on each page should have alternating background colours to make it clear when one comment finishes and another begins. I am using this CSS to achieve it
.comment:nth-child(2n+1){background-color:rgba(0,0,0,0.075)}
So it is my understanding that the first, third, etc comments should be light grey while second, fourth, etc will have a white background.
The first article I created has one comment at the bottom and it is grey as expected. The second article also has one comment but that has a white background. Using the code inspector in Chrome shows that it is not picking up the "nth-child" line of CSS. When I temporarily added a second dummy comment it had a grey background, so it seems to be applying to even elements instead of odd ones.
I have read the many similar questions on here but none of them got me to a solution. I have tried nth-child(odd) instead of nth-child(2n+1) but it made no difference. I even tried wrapping all the comments in another div and using this CSS instead, but that really messed things up by applying itself to nested paras within the comments.
.comment-wrapper :nth-child(2n+1){background-color:rgba(0,0,0,0.075)}
Any practical suggestions would be so appreciated. Thanks.