Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply style with percentage in Angular?

As per this link

I can do

<p [style.width.px]="30">
  Some text that may be important.
</p>

This will set a width of 30 px. How do I do the same for percentage ?

<p [style.width.percent]="30"> // This doesn't work
  Some text that may be important.
</p>
like image 227
dota2pro Avatar asked Jun 06 '19 19:06

dota2pro


People also ask

Can I use the percent symbol for in-line styles in angular?

This is a super minor post; but, I just used the "%" (percent) symbol for in-line styles in Angular 4.2.3, and it totally worked. It's just another example of how the Angular template syntax is such a joy to work with.

How do I use style in angular 12?

Angular 9, Angular 10, Angular 11, Angular 12 The syntax of the style binding is similar to the property binding. The Style Binding uses the [] brackets. Place the CSS Style property (binding target) inside the square bracket. The CSS Style property must begin with ‘Style’ followed by a dot (.) and then style name.

How to convert a number to a percentage in angular?

Angular PercentPipe is an angular Pipe API that formats a number as a percentage according to locale rules. It belongs to CommonModule. Find the syntax. Find the description. number_expression: An angular expression that will give output a number. percent : A pipe keyword that is used with pipe operator and it converts number into percent.

What is percentpipe in angular?

Angular PercentPipe is an angular Pipe API that formats a number as a percentage according to locale rules. It belongs to CommonModule.


1 Answers

You use the % symbol.

<p [style.width.%]="30">

You use what ever would normally come after the numeric value in CSS.

For example;

30rem => [style.width.rem]="30"
30px => [style.width.px]="30"
30% => [style.width.%]="30"
like image 98
Reactgular Avatar answered Sep 19 '22 21:09

Reactgular