Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a Stylus variable in calc?

In Stylus, how do I use a variable in a calc expression?

For example, the following doesn't work (arrow-size being a variable):

arrow-size = 5px
left calc(50% - arrow-size)
like image 325
aknuds1 Avatar asked Aug 28 '15 13:08

aknuds1


2 Answers

In order to use a Stylus variable inside a calc expression, one must employ the string % operator:

arrow-size = 5px
left "calc(50% - %s)" % arrow-size
like image 140
aknuds1 Avatar answered Nov 16 '22 06:11

aknuds1


To use multiple variables (not just one) in calc (or with other functions), i use sprintf as you used, but with tuples:

arrow-size = 5px
measure = 50%
left "calc(%s - %s)" % (measure arrow-size)

Remember that interpolation in Stylus is supported through {} and it's used for other kind of interpolation. It's used to surround an expression, which then becomes part of a identifier, or a selector.

like image 36
Facundo Victor Avatar answered Nov 16 '22 06:11

Facundo Victor