Is something like this possible?
div[id^=red]:hover {
color: (/red/);
}
<div id="red"></div>
You can't do this with CSS only, but if you can edit the HTML there are workarounds.
The first option is to add a class that represents a color and style it accordingly, this is not very efficient, but it does the job. Of course, it wont work if your colors are dynamic:
div {
width: 100px;
height: 100px;
background: grey;
}
.red:hover {
background: red;
}
.blue:hover {
background: blue;
}
.green:hover {
background: green;
}
<div class="red"></div>
<div class="blue"></div>
<div class="green"></div>
Another tricky solution, since you plan to use :hover, is to set the color and override it on the idle state:
div {
width: 100px;
height: 100px;
}
div:not(:hover) {
background: grey !important;
}
<div style="background: red;"></div>
<div style="background: blue;"></div>
<div style="background: #fa8732;"></div>
<div style="background: #bb0099;"></div>
HTML and you don't have to worry for the CSS.
Of course this will work for any property.
attr()function which can access the element's attributes, however you can only use it to affect the content property of a before/after pseudo element.