question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Best way to put variables inside of calc?

See original GitHub issue

Right now I’m doing width: s('calc(100% * %s)', $fraction) but that gets really hairy when I have several variables.

We should probably standardize variable interpolation as well. I think Sass does this pretty well. Their version looks like: width: calc(100% * #{$fraction}); and is much more readable/enjoyable to work with.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:3
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Panyacommented, Feb 3, 2016

You can simplify it a bit:

width: 'calc(100% * %s)' % $fraction

We’ll change syntax of interpolation (see #728), so Sass’ variant will be possible.

0reactions
corysimmonscommented, Aug 15, 2016

@Panya Thoughts on adding better interpolation?

Something similar to this syntax would be awesome:

$fraction: 1/2

.column
  width: calc(100% * {$fraction})

// returns
.column {
  width: calc(100% * 1/2); // note it doesn't convert 1/2 to .5 automagically
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Sass Variable in CSS calc() function - Stack Overflow
To use $variables inside your calc() of the height property: ... Here is a really simple solution using SASS/SCSS and a math formula...
Read more >
Using CSS variables inside `calc()` - CodePen
Insecure Resource. The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https....
Read more >
calc() - CSS: Cascading Style Sheets - MDN Web Docs
The calc() CSS function lets you perform calculations when specifying CSS property values. It can be used with , , , , ,...
Read more >
SASS Variable in CSS calc() function - GeeksforGeeks
Using a Sass variable inside calc() function: Variables in CSS have the ability to have different values for different elements but Sass ...
Read more >
How and when to use CSS calc(): Tutorial with examples
In this tutorial, we'll get to know the CSS calc() function, why it's useful, and how to use it in your projects.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found