快应用richtext组件背景色填充问题
现象描述:
车机上是深色背景模式,使用richtext包裹网页内容时,出现白色背景边框,影响整体深色背景,问题截图如下:

问题代码:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
<richtext type="html" class="rich-text">{{content}}</richtext><script> export default { private: { content: <body style="#006000;"> <div class="item-content" style="#006000;"> <style>h1{color: yellow;}</style> <p class="item-title">h1</p> <h1>文本测试</h1> <p class="item-title">h2</p> <h2>文本测试</h2> </div> </body> }, }</script><style>.rich-text { #cd853f; }</style> |
问题分析:
车机上在使用richtext组件包裹html内容后,在快应用里通过class设置background-color是不生效的。如果richtext包裹的内容只含网页的body部分,即使在body上设置了背景色,在展示富文本时周围也会出现一圈白色边框。需要在richtext里写完整的html,且在其html标签上设置背景色,背景色在展示时才能覆盖边框,不会出现白色的空隙。
解决方法:
在richtext里包裹一个完整的html格式的网页,html标签中设置背景色。
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
<richtext type="html" class="rich-text">{{content}}</richtext><script> export default { private: { content: `<!DOCTYPE html> <html lang="en" style="#006000;"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> </head> <body> <div class="item-content"> <style>h1{color: yellow;}</style> <p class="item-title">h1</p> <h1>文本测试</h1> <p class="item-title">h2</p> <h2>文本测试</h2> </div> </body> </html>` }, }</script><style>.rich-text { #cd853f;}</style> |
修改后效果图如下:

原链接:https://developer.huawei.com/consumer/cn/forum/topic/0204429221972080033?fid=18
原作者:Mayism
浙公网安备 33010602011771号