# A little help with a CSS selector?

**URL:** https://meta.discourse.org/t/a-little-help-with-a-css-selector/356153
**Category:** Support
**Created:** [March 6, 2025, 8:37pm UTC](https://meta.discourse.org/t/a-little-help-with-a-css-selector/356153 "2025-03-06T20:37:27Z")
**Posts on this page:** 19
**Page:** 1

<div class="post-metadata">

### Author: ![Turtle](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/turtle/32/476220_2.png) [@Turtle](https://meta.discourse.org/u/Turtle)
#### Post date: [March 6, 2025, 8:37pm UTC](https://meta.discourse.org/t/a-little-help-with-a-css-selector/356153/1 "2025-03-06T20:37:27Z")

</div>

Hey,  
Since there’s no shield icon or any indication of being a staff user for messages in chat, I wanted to slightly color their usernames. I found the selector but I ran into trouble figuring out a way to select staff users. Here’s what I have right now:

```plaintext
.chat-message-info __username__ name {
  color: #c3e7eb;
}

```

Is there any way to make this work, and if so, how? Thanks!

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [March 6, 2025, 9:02pm UTC](https://meta.discourse.org/t/a-little-help-with-a-css-selector/356153/3 "2025-03-06T21:02:05Z")

</div>

You can use:

```css
.chat-message-info__username.is-staff {
  .chat-message-info __username__ name {
     color: #c3e7eb;
  }
}

```

![image](https://global.discourse-cdn.com/meta/original/4X/c/d/9/cd9eda096ebf213bb0dbbf2fff5ddd3ac1d18aa4.png)

---

<div class="post-metadata">

### Author: ![Turtle](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/turtle/32/476220_2.png) [@Turtle](https://meta.discourse.org/u/Turtle)
#### Post date: [March 6, 2025, 9:26pm UTC](https://meta.discourse.org/t/a-little-help-with-a-css-selector/356153/4 "2025-03-06T21:26:05Z")

</div>

Thank you! Well, can’t believe I missed that.

---

<div class="post-metadata">

### Author: ![Turtle](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/turtle/32/476220_2.png) [@Turtle](https://meta.discourse.org/u/Turtle)
#### Post date: [March 7, 2025, 8:19pm UTC](https://meta.discourse.org/t/a-little-help-with-a-css-selector/356153/5 "2025-03-07T20:19:02Z")

</div>

Oh, one more question. What would the thing be for trust level four users?  
To clarify, I also would like to do something similar for users with trust level four. I couldn’t find a selector for it.

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [March 8, 2025, 8:15pm UTC](https://meta.discourse.org/t/a-little-help-with-a-css-selector/356153/6 "2025-03-08T20:15:08Z")

</div>

From what I see in the code, you can expect to see the following classnames:

- `is-staff`
- `is-admin`
- `is-moderator`
- `is-new-user`
- `group--primary_group_name`

You could create a group and set it as the primary group.

You can also use some code to add the missing class names.

```js
import { apiInitializer } from "discourse/lib/api";

export default apiInitializer((api) => { 
  // Add the groups you wants to add
  const allowedGroups = ["trust_level_4"];

  api.modifyClass("components:chat/message/info", () => {
    return class extends SuperClass {
      @service currentUser;
      
      get usernameClasses() {
        if (!this.currentUser) {
          return super.usernameClasses;
        }
        const allowedGroupClasses = this.currentUser.groups
          .filter((g) => allowedGroups.includes(g.name))
          .map((g) => `group--${g.name}`)
          .join(" ");
      
        return super.usernameClasses + " " + allowedGroupClasses;
      }
    }
  })
});

```

 ![A screenshot of a webpage editor showing code editing options for CSS, JavaScript, and sections like <head>, before header, after header, and footer. (Captioned by AI)](https://global.discourse-cdn.com/meta/original/4X/8/4/d/84d9c762fe8bbc87fe550a48607020470540a1a6.png)

Then you can CSS target with `.group--trust_level_4`.

Example:

```css
.chat-message-info__username.group--trust_level_4 {
    .chat-message-info __username__ name {
        color: blue;
    }
}

```

For username, you don’t need the code above:

```css
.chat-message-info__username.[data-user-card="username_here"] {
    .chat-message-info __username__ name {
        color: red;
    }
}

```

---

<div class="post-metadata">

### Author: ![Turtle](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/turtle/32/476220_2.png) [@Turtle](https://meta.discourse.org/u/Turtle)
#### Post date: [March 8, 2025, 8:22pm UTC](https://meta.discourse.org/t/a-little-help-with-a-css-selector/356153/7 "2025-03-08T20:22:25Z")

</div>

> [@Arkshine](#):
>
> `group--trust_level_4`

Can I select a specific username instead of trust level four? Thanks so much by the way, this is a very well written response.

Sorry for the questions, I’m not great with code.

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [March 8, 2025, 8:35pm UTC](https://meta.discourse.org/t/a-little-help-with-a-css-selector/356153/8 "2025-03-08T20:35:25Z")

</div>

I’ve updated the code above.  
It will include the username with `.user--username`.  
Note that you can use the ID if you prefer.

---

<div class="post-metadata">

### Author: ![Turtle](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/turtle/32/476220_2.png) [@Turtle](https://meta.discourse.org/u/Turtle)
#### Post date: [March 8, 2025, 8:40pm UTC](https://meta.discourse.org/t/a-little-help-with-a-css-selector/356153/9 "2025-03-08T20:40:59Z")

</div>

Can you give an example of it with my username for example changing color?

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [March 8, 2025, 8:46pm UTC](https://meta.discourse.org/t/a-little-help-with-a-css-selector/356153/10 "2025-03-08T20:46:06Z")

</div>

![The image shows HTML code for a chat window selection interface in Slack with classes for user display and button styling. (Captioned by AI)](https://global.discourse-cdn.com/meta/original/4X/e/e/3/ee3ed72e74134126d394fe2e00e396c8a0735cf1.png)

```css
.chat-message-info__username.user--arkshine {
    .chat-message-info __username__ name {
        color: red;
    }
}

```

---

<div class="post-metadata">

### Author: ![Turtle](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/turtle/32/476220_2.png) [@Turtle](https://meta.discourse.org/u/Turtle)
#### Post date: [March 8, 2025, 8:48pm UTC](https://meta.discourse.org/t/a-little-help-with-a-css-selector/356153/11 "2025-03-08T20:48:30Z")

</div>

> [@Arkshine](#):
>
> ```plaintext
> .chat-message-info__username.user--arkshine {
> .chat-message-info __username__ name {
> color: red;
> }
> }
> 
> ```

Hm, it won’t work for a user called Kat\_Mac?

```plaintext
.chat-message-info__username.user--kat_mac {
    .chat-message-info __username__ name {
        color: red;
    }
}

```

I have the updated JS.

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [March 8, 2025, 8:52pm UTC](https://meta.discourse.org/t/a-little-help-with-a-css-selector/356153/12 "2025-03-08T20:52:05Z")

</div>

If the username is “Kat\_Mac”, then the CSS should be `user--Kat_Mac`.

---

<div class="post-metadata">

### Author: ![Turtle](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/turtle/32/476220_2.png) [@Turtle](https://meta.discourse.org/u/Turtle)
#### Post date: [March 8, 2025, 8:55pm UTC](https://meta.discourse.org/t/a-little-help-with-a-css-selector/356153/13 "2025-03-08T20:55:59Z")

</div>

Hm, I still cannot get it to work. All I have to include in the JS part is the username Kat\_Mac, correct?

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [March 8, 2025, 9:00pm UTC](https://meta.discourse.org/t/a-little-help-with-a-css-selector/356153/14 "2025-03-08T21:00:36Z")

</div>

No, don’t change the JS. If you refer to `includeUsersField,` it means whether you want to show by “username” (e.g. Kat\_Mac) or by “id” (e.g. like 4). If you wish to show the username, leave it as it is.

---

<div class="post-metadata">

### Author: ![Turtle](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/turtle/32/476220_2.png) [@Turtle](https://meta.discourse.org/u/Turtle)
#### Post date: [March 8, 2025, 9:02pm UTC](https://meta.discourse.org/t/a-little-help-with-a-css-selector/356153/15 "2025-03-08T21:02:33Z")

</div>

Either way, it still won’t work. Thanks for your help though.

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [March 8, 2025, 9:03pm UTC](https://meta.discourse.org/t/a-little-help-with-a-css-selector/356153/16 "2025-03-08T21:03:58Z")

</div>

It does work for me:

 ![This image shows a screenshot of a code editing interface displaying HTML and JavaScript code for a chat application highlighting user messages and their corresponding styles. (Captioned by AI)](https://global.discourse-cdn.com/meta/original/4X/5/0/c/50c7c27168ea1f36ac27b50a5d985ad0739b8460.png)

Make sure you’re using the latest JS code, and you did update properly the CSS!

* * *

@Turtle Ignore my code, actually I did not see there an attribute with the username you can use.

```css
.chat-message-info__username[data-user-card="Kat_Mac"] {
    .chat-message-info __username__ name {
        color: red;
    }
}

```

---

<div class="post-metadata">

### Author: ![Turtle](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/turtle/32/476220_2.png) [@Turtle](https://meta.discourse.org/u/Turtle)
#### Post date: [March 8, 2025, 9:06pm UTC](https://meta.discourse.org/t/a-little-help-with-a-css-selector/356153/17 "2025-03-08T21:06:51Z")

</div>

This is all I’ve got.

 ![Screenshot 2025-03-08 at 16.06.13](https://global.discourse-cdn.com/meta/original/4X/9/9/4/9946a95467328e32c4d43ab5fa48bd5118fe96dc.png)  
 ![Screenshot 2025-03-08 at 16.06.37](https://global.discourse-cdn.com/meta/original/4X/f/6/0/f6037d65f680c88bd5134f9594bfe9fa8748a39b.png)  
I don’t know what could be the problem.

---

<div class="post-metadata">

### Author: ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)
#### Post date: [March 8, 2025, 9:07pm UTC](https://meta.discourse.org/t/a-little-help-with-a-css-selector/356153/18 "2025-03-08T21:07:41Z")

</div>

Use this CSS:

```css
.chat-message-info__username[data-user-card="Kat_Mac"] {
    .chat-message-info __username__ name {
        color: red;
    }
}

```

---

<div class="post-metadata">

### Author: ![Turtle](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/turtle/32/476220_2.png) [@Turtle](https://meta.discourse.org/u/Turtle)
#### Post date: [March 8, 2025, 9:08pm UTC](https://meta.discourse.org/t/a-little-help-with-a-css-selector/356153/19 "2025-03-08T21:08:27Z")

</div>

> [@Arkshine](#):
>
> ```plaintext
> .chat-message-info__username[data-user-card="Kat_Mac"] {
> .chat-message-info __username__ name {
> color: red;
> }
> }
> 
> ```

That worked, thanks!

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [April 7, 2025, 9:08pm UTC](https://meta.discourse.org/t/a-little-help-with-a-css-selector/356153/20 "2025-04-07T21:08:28Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
