poashoas
poashoas

Reputation: 1894

sass percentage of a number

I am stuck here. I want to calculate 2/3 of 10rem like this:

$percentage : percentage(2/3); // 66.666667%
$width      : 10rem;
$calculate  : do magic: 66.666667% of 10rem;
 
img { max-height: calc( 100vh - $calculate ); }

I have been looking in the SASS documentation. I can only find some stuff about math function and not too much about percentage.

Upvotes: 0

Views: 551

Answers (1)

Hans Spieß
Hans Spieß

Reputation: 935

The percentage(2/3) function call appends a %. You can not multiply that with a non-unitless value like 10rem. Instead, calculate it directly like:

img { 
    max-height: calc(100vh - #{2/3 * 10rem});
}

The #{} (interpolation) is needed to render the result of the calculation inside the Css calc() expression.

Read more on...

Upvotes: 1

Related Questions