How can I use a negative variables in Stylus ?
I write mixin for a sprite:
sprite-medium(col,row)
width = 40px
height = 40px
width: width
height: height
background: url('../img/medium-sprite.png') no-repeat
background-position: -col*width -row*height
And I have an error. Of course I can write negative values in call of mixins, but it's not a perfect decision. Anyone can help? Thanks.
Stylus is treating the - before col and row as part of the name - they need to be separated for that to work like -(col * width), however you also need to avoid subtracting the two values that you want for background position. Here's a solution with a working background calculation and a bit simplified through the use of property lookups:
sprite-medium(col, row)
width: 40px
height: 40px
background: url('../img/medium-sprite.png') no-repeat
background-position: -(col * @width) -1 * (row * @height)
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With