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为什么生效
1368浏览 • 1回复 待解决
HarmonyOS 下面demo为什么点击刷新?
748浏览 • 1回复 待解决
HarmonyOS margin生效
1137浏览 • 1回复 待解决
HarmonyOS expandSafeArea生效
1022浏览 • 1回复 待解决
HarmonyOS margin生效问题
732浏览 • 1回复 待解决
HarmonyOS @Observed生效问题
1252浏览 • 1回复 待解决
HarmonyOS targetSpace生效问题
565浏览 • 1回复 待解决
abiFilters配置生效
994浏览 • 1回复 待解决
HarmonyOS Web组件borderRadius生效
735浏览 • 1回复 待解决
HarmonyOS Stack 里 align生效
698浏览 • 1回复 待解决
HarmonyOS photoViewPicker智能推荐生效
940浏览 • 1回复 待解决
HarmonyOS 关于onKeyEvent生效问题
1036浏览 • 1回复 待解决
HarmonyOS Span内边距生效
428浏览 • 1回复 待解决
HarmonyOS stack设置圆角生效
662浏览 • 1回复 待解决