HarmonyOS 为什么calc不生效呢

.width (`calc( (100%-54) /4)`)
  • 1.

这种为什么不生效?

设置成这种才生效:

.width ("20%")
  • 1.
HarmonyOS
2025-01-09 17:28:28
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
aquaa

calc的使用语法为.width(‘calc((100% - 54vp)/2)’),可以参考示例如下:

// xxx.ets
@Entry
@Component
struct SizeExample {
  build() {
    Column({ space: 10 }) {
      // calc计算特性
      Text('calc:').fontSize(20).fontColor('#999').width('90%')
      Text('calc test')
        .fontSize(30)
        .fontWeight(FontWeight.Bold)
        .backgroundColor(0xFFFAF0)
        .textAlign(TextAlign.Center)
        .margin('calc(10vp*2)')
        .width('calc((100% - 54vp)/2)')
      // width和height设置百分比时,以父容器的width和height作为基础值。
      /*.size({ width: 'calc(90%)', height: 'calc(50vp + 10%)' })*/
    }.width('100%').margin({ top: 5 })
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
分享
微博
QQ
微信
回复
2025-01-09 18:52:58


相关问题
Left、Top为什么生效
1657浏览 • 1回复 待解决
Span设置backGroundColor生效为什么
1196浏览 • 1回复 待解决
HarmonyOS 下面demo为什么点击刷新?
1013浏览 • 1回复 待解决
为什么数组下标越界闪退?
259浏览 • 0回复 待解决
HarmonyOS margin生效
1431浏览 • 1回复 待解决
HarmonyOS expandSafeArea生效
1408浏览 • 1回复 待解决
HarmonyOS @Observed生效问题
1551浏览 • 1回复 待解决
HarmonyOS margin生效问题
1041浏览 • 1回复 待解决
HarmonyOS targetSpace生效问题
801浏览 • 1回复 待解决
abiFilters配置生效
1330浏览 • 1回复 待解决
HarmonyOS 关于onKeyEvent生效问题
1369浏览 • 1回复 待解决
HarmonyOS Web组件borderRadius生效
1044浏览 • 1回复 待解决
HarmonyOS Stack 里 align生效
986浏览 • 1回复 待解决
HarmonyOS Span内边距生效
717浏览 • 1回复 待解决