span只支持“文本通用属性”,不支持“通用属性”。而height、width、padding、margin 属于通用属性目前可以使用Text包裹span,然后设置Text的padding、margin 属性。demo如下:@Entry @Component struct Index { @State message: string = 'Hello World'; build() { Row() { ImageSpan($r('app.media.startIcon')) .width(40) .margin({ left: 10 })// 这个能生效 .padding(5) // 这个也能生效 Text() { Span("一个带背景的span,padding不生效") .fontColor(Color.Blue) .onClick(() => { console.log('subspan clicked') }) } .padding(20)// .margin({ left: 20 })// .backgroundColor(Color.Red) .borderRadius(30) }.width('100%') .height('100%') } }ImageSpan的通用属性方法支持尺寸设置、背景设置、边框设置。https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-imagespan-V5\#属性其中尺寸设置包含padding、marginhttps://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-universal-attributes-size-V5\#paddingspan :通用属性方法仅支持文本通用https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-span-V5\#属性文本通用:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-universal-attributes-text-style-V5
span只支持“文本通用属性”,不支持“通用属性”。而height、width、padding、margin 属于通用属性
目前可以使用Text包裹span,然后设置Text的padding、margin 属性。
demo如下:
ImageSpan的通用属性方法支持尺寸设置、背景设置、边框设置。
https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-imagespan-V5\#属性
其中尺寸设置包含padding、margin
https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-universal-attributes-size-V5\#padding
span :通用属性方法仅支持文本通用
https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-basic-components-span-V5\#属性
文本通用:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-universal-attributes-text-style-V5