# How can I add a custom class to every 2nd message?

**URL:** <https://meta.discourse.org/t/how-can-i-add-a-custom-class-to-every-2nd-message/49990>\
**Category:** Support\
**Created:** [Septembre 11, 2016, 7:37 UTC](https://meta.discourse.org/t/how-can-i-add-a-custom-class-to-every-2nd-message/49990 "2016-09-11T19:37:43Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)\
**Post date:** [Septembre 11, 2016, 8:30 UTC](https://meta.discourse.org/t/how-can-i-add-a-custom-class-to-every-2nd-message/49990/4 "2016-09-11T20:30:49Z")

</div>

> [@ziptofaf](#):
>
> As the different color will spread way too much to the right and it looks poorly

That’s just basic CSS and a result of not targeting the correct element.

“small action” posts can be excluded from the styling easily enough by specifying the class value “topic-post”, but the odd-even uses the element regardless of the class attribute ☹

```plaintext
div.post-stream > div.topic-post:nth-child(2n) div.topic-body {
  background-color: #bde;
}
div.post-stream > div.topic-post:nth-child(2n+1) div.topic-body {
  background-color: #edb;
}

```

 ![](https://global.discourse-cdn.com/meta/original/3X/3/7/37be961df7a3e82632dbe60b955b8d8e569a9df8.png)

---

_[View the full topic](https://meta.discourse.org/t/how-can-i-add-a-custom-class-to-every-2nd-message/49990)._
