# CSS 在 HTML 的 ID 属性中

**URL:** https://meta.discourse.org/t/css-in-id-html-atribute/79941
**Category:** Support
**Created:** [2018年二月6日 19:22 UTC](https://meta.discourse.org/t/css-in-id-html-atribute/79941 "2018-02-06T19:22:07Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![luckydev](https://avatars.discourse-cdn.com/v4/letter/l/eb8c5e/32.png) [@luckydev](https://meta.discourse.org/u/luckydev)
#### Post date: [2018年二月6日 19:22 UTC](https://meta.discourse.org/t/css-in-id-html-atribute/79941/1 "2018-02-06T19:22:07Z")

</div>

Hello!  
How to add CSS to “ID = 5”?

`<tr data-category-id="5" class="has-description no-logo">`

---

<div class="post-metadata">

### Author: ![awesomerobot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/awesomerobot/32/142900_2.png) [@awesomerobot](https://meta.discourse.org/u/awesomerobot)
#### Post date: [2018年二月6日 19:37 UTC](https://meta.discourse.org/t/css-in-id-html-atribute/79941/2 "2018-02-06T19:37:04Z")

</div>

You can target data attributes with CSS like this:

```CSS
tr[data-category-id="5"] {
    background: red;
}

```

---

<div class="post-metadata">

### Author: ![luckydev](https://avatars.discourse-cdn.com/v4/letter/l/eb8c5e/32.png) [@luckydev](https://meta.discourse.org/u/luckydev)
#### Post date: [2018年二月6日 19:41 UTC](https://meta.discourse.org/t/css-in-id-html-atribute/79941/3 "2018-02-06T19:41:08Z")

</div>

This not working(

 ![](https://global.discourse-cdn.com/meta/original/3X/7/b/7bdd95b1ad2988833d76126b1063bf74c02fb040.jpg)

---

<div class="post-metadata">

### Author: ![luckydev](https://avatars.discourse-cdn.com/v4/letter/l/eb8c5e/32.png) [@luckydev](https://meta.discourse.org/u/luckydev)
#### Post date: [2018年二月6日 19:41 UTC](https://meta.discourse.org/t/css-in-id-html-atribute/79941/4 "2018-02-06T19:41:57Z")

</div>

I want each category to have its own background color

---

<div class="post-metadata">

### Author: ![awesomerobot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/awesomerobot/32/142900_2.png) [@awesomerobot](https://meta.discourse.org/u/awesomerobot)
#### Post date: [2018年二月6日 19:48 UTC](https://meta.discourse.org/t/css-in-id-html-atribute/79941/5 "2018-02-06T19:48:12Z")

</div>

That CSS works for me on the category page to change the background color — is that where you’re trying to change it? Is it possible to provide a link to the page you’re trying to change?

---

<div class="post-metadata">

### Author: ![luckydev](https://avatars.discourse-cdn.com/v4/letter/l/eb8c5e/32.png) [@luckydev](https://meta.discourse.org/u/luckydev)
#### Post date: [2018年二月6日 19:52 UTC](https://meta.discourse.org/t/css-in-id-html-atribute/79941/6 "2018-02-06T19:52:16Z")

</div>

![](https://global.discourse-cdn.com/meta/original/3X/d/8/d8abe6e0dc81cd2ca684b6c7af5fe37b0a2a403c.jpg)

How do I give my background color to each category?

---

<div class="post-metadata">

### Author: ![awesomerobot](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/awesomerobot/32/142900_2.png) [@awesomerobot](https://meta.discourse.org/u/awesomerobot)
#### Post date: [2018年二月6日 20:01 UTC](https://meta.discourse.org/t/css-in-id-html-atribute/79941/7 "2018-02-06T20:01:07Z")

</div>

Hmm, I’m not quite sure why the provided CSS wouldn’t work for you… here’s an example I’m able to build.

 ![11%20PM](https://global.discourse-cdn.com/meta/original/3X/3/9/39386703d7b607434d144df4d75709a30beed3aa.png) ![00%20PM](https://global.discourse-cdn.com/meta/original/3X/9/7/97c220cd878a87efa84b2daab8a2a9f52607418b.png)

---

<div class="post-metadata">

### Author: ![luckydev](https://avatars.discourse-cdn.com/v4/letter/l/eb8c5e/32.png) [@luckydev](https://meta.discourse.org/u/luckydev)
#### Post date: [2018年二月6日 20:06 UTC](https://meta.discourse.org/t/css-in-id-html-atribute/79941/8 "2018-02-06T20:06:02Z")

</div>

Thanks! It works 😀

---

<div class="post-metadata">

### Author: ![j.jaffeux](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j.jaffeux/32/60297_2.png) [@j.jaffeux](https://meta.discourse.org/u/j.jaffeux)
#### Post date: [2018年二月6日 21:22 UTC](https://meta.discourse.org/t/css-in-id-html-atribute/79941/9 "2018-02-06T21:22:15Z")

</div>


