0

Assume I want the following styling:

font-size: 3rem;

However, I do not want to hardcode the 3. Rather, I want it to be a result of a calc() operation (e.g. calc(2 + 1)). How do I specify the unit rem to follow the results of the calc() operation? I'm trying to do something like this:

font-size: calc(2 + 1)rem;

I guess I'm looking for a concatenation feature? CSS solution only, please.

StackOverflowNewbie
  • 39,403
  • 111
  • 277
  • 441

2 Answers2

2

In the comments you mentioned variables. So the answer from here may be useful.

Use variable in calc and multiply it by 1 with the needed unit:

font-size: calc(var(--size) * 1rem);
Ivan Beliakov
  • 529
  • 3
  • 14
0

Not sure why you'd want to do this, but you could:

font-size: calc((2 + 1) * 1rem);
ray
  • 26,557
  • 5
  • 28
  • 27