Now this is possible with custom properties:
.brown { --rgb: 118, 76, 41; } .green { --rgb: 51, 91, 11; } a { display: block; position: relative; } div { position: absolute; bottom: 0; background-color: rgba(var(--rgb), 0.8); } a:hover div { background-color: rgba(var(--rgb), 1); }
To understand how this works, see How do I apply opacity to a CSS color variable?
If custom properties are not an option, see Original answer below.
Unfortunately, no, you will have to re-specify the values of red, green and blue for each individual class:
a { display: block; position: relative; } .brown { position: absolute; bottom: 0; background-color: rgba(118, 76, 41, 0.8); } a:hover .brown { background-color: rgba(118, 76, 41, 1); } .green { position: absolute; bottom: 0; background-color: rgba(51, 91, 11, 0.8); } a:hover .green { background-color: rgba(51, 91, 11, 1); }
Only one inherit keyword can be used as a property value, and even then using inherit is inappropriate here.
BoltClock Aug 05 '11 at 20:52 2011-08-05 20:52
source share