0

Is it possible that i can change the CSS of a parent element according to a html ID of a child, for example:

<div class="blog">
  <div class="row">
    <div class="blog-post" id="post-!XX!">
    </div>
  </div>
</div>

Current CSS:

.blog{
  background-color:white;
}

So background color of blog is white by default.

So if i have 3 posts for example, ID post-1, post-2 and post-3 and i want the background-color of .blog to be black on post-2, but for the rest it needs to be default (white).

Can someone tell me if this is possible, and how to?

  • If all of the posts have the `.blog-post` class, you should be able to control the even posts with `.blog-post:nth-child(2n) { background: black; }` – sbeliv01 Jan 31 '17 at 15:55
  • @sbeliv01 But i dont want .blog-post to have a black background, i want the first div with class .blog to have a black background – Sven Jansen Jan 31 '17 at 16:19

0 Answers0