How do properly use css's "calc()' with ng-style

11,313

Solution 1

.logo-area(ng-style="{'right': 'calc(50% - '+{{fixedWidth}}+'px'+')'}")

Will solve the problem.

Solution 2

This worked for me in HTML with Angular 8

[ngStyle]="{'width': someAngularVariable +'px', 'left': 'calc(100% - ' +someAngularVariable + 'px)' }"
Share:
11,313
zihaow
Author by

zihaow

I am a developer as well as a photographer.

Updated on August 20, 2022

Comments

  • zihaow
    zihaow almost 2 years

    I have the following inline-styling using Angular's ng-style and css's "calc()', but it didn't work. Can anyone tell me what's wrong?

    // my jade file has a class named '.logo-area'. 
    .logo-area(ng-style="{'right':'calc(100% -'+({{fixedWidth}}+'px') +')'}")
    
  • Mr Lister
    Mr Lister over 8 years
    You should explain why changing the percentage will solve the problem.
  • semiintel
    semiintel over 6 years
    The difference is a removed pair of parentheses.