【问题标题】:How to apply style with percentage in Angular?如何在 Angular 中应用带有百分比的样式?
【发布时间】:2023-03-06 11:11:01
【问题描述】:

据此link

我可以的

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

这将设置宽度为 30 像素。 我如何为百分比做同样的事情?

<p [style.width.percent]="30"> // This doesn't work
  Some text that may be important.
</p>

【问题讨论】:

标签: angular typescript


【解决方案1】:

您使用% 符号。

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

您使用通常会出现在 CSS 中数值之后的内容。

例如;

30rem => [style.width.rem]="30"
30px => [style.width.px]="30"
30% => [style.width.%]="30"

【讨论】:

  • 哇,使用 Angular 真是太酷了,因为 beta 甚至都不知道他们有这个功能。
猜你喜欢
  • 2021-01-30
  • 1970-01-01
  • 2017-08-19
  • 1970-01-01
  • 1970-01-01
  • 2018-11-27
  • 1970-01-01
  • 2020-03-22
  • 2019-01-14
相关资源
最近更新 更多