Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2: How to use css calc() with some component value?

I want to calculate div height based on the component value by using calc CSS function. The error it gave me:

TypeError: co.calc is not a function

My code:

<div [ngStyle]="{'height': calc(100% - + assetScreenSize + px)}">
</div>
like image 584
PARAMANANDA PRADHAN Avatar asked Aug 02 '17 09:08

PARAMANANDA PRADHAN


People also ask

How does the CALC () function work on values in CSS?

The calc() function takes a single expression as its parameter, with the expression's result used as the value. The expression can be any simple expression combining the following operators, using standard operator precedence rules: + Addition.

Can I use Calc in padding?

This is also how you can create aspect-ratio locked divs in HTML since you can calculate height from width using padding-top with a percentage value. A solution for you would be to use CSS calc, it has good browser support and fixes your issue in quite a simple manner.

How do you debug a CSS calculator?

An, albeit hacky, way to debug calc() is using Developer Tools in your browser. With DevTools open, select the element you want to apply calc() on, and add a CSS property width to it with the calc() expression.

How do you use calculator in style?

Using the calc() function in inline styles in React #Set the style prop on the element. Pass the result of calling calc() as the value for a CSS property. The call to calc() should be wrapped in a string, e.g. 'calc(100% - 600px)' .


1 Answers

Your syntax is incorrect. The correct way would be:

<div [ngStyle]="{'height': 'calc(100% -' + assetScreenSize + 'px)'}">
</div>
like image 131
Aslam Avatar answered Oct 08 '22 15:10

Aslam