0

Is it possible in CSS to set the value of one property of a class as the same property value of another class ?

e.g.:

.classA{
color: blue;
}
.classB{
color:[likeClassA];
}

Rob
  • 14,746
  • 28
  • 47
  • 65
  • 2
    Use [variables](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties). – BenM Nov 25 '19 at 13:42
  • 1
    Note, what you're referring to are CSS "properties" and not "attributes". – Sean Nov 25 '19 at 13:45

2 Answers2

1

it is not possible but you could do this as an alternative

.classA ,.class B{ color:blue; }

Twage Mwakajumba
  • 68
  • 1
  • 1
  • 10
0

With pure CSS (i.e. not a precompiled solution) you can use CSS custom properties:

:root {
   --mycolor: blue;
}

.classA {
   color: var(--mycolor);
}

.classB {
   color: var(--mycolor);
}

Read more: https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties


Please note that var() is not supported in IE11 or below. There are some solutions though including polyfills: CSS custom properties polyfill for ie11

Jeremy Harris
  • 24,318
  • 13
  • 79
  • 133