Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

新增 小程序端渲染表格边框时支持渲染自带的边框颜色与线型设置 #439

Merged
merged 1 commit into from
Jul 15, 2022

Conversation

zouxingjie
Copy link
Contributor

No description provided.

@jin-yufeng jin-yufeng merged commit 06a5168 into jin-yufeng:master Jul 15, 2022
@jin-yufeng
Copy link
Owner

css 里的 border-colorborder-style 本来就支持的

@zouxingjie
Copy link
Contributor Author

css 里的 border-colorborder-style 本来就支持的

最近有个项目刚好用到发现在富文本里设置的边框颜色与线型在小程序里没有效果,后来看了下源码发现在解析的时候直接默认设置了 border: xxx solid gray; 应该是这个样式导致了table原本自带的边框颜色与线型没有渲染出来。所以提交了这个合并,亲测是正常的。

@jin-yufeng
Copy link
Owner

源码里设置 border: xxx solid gray 是用于 border 属性的渲染,如果设置了 border 属性,就设置这么宽的边框
属性样式的优先级低于 style,不影响在 style 里设置 border-colorborder-style,传入这样的 html 是有效的

<table style="border-width:1px;border-style:solid;border-color: red">
<td>1</td>
</table>

没有效果是怎么设置的

@zouxingjie
Copy link
Contributor Author

源码里设置 border: xxx solid gray 是用于 border 属性的渲染,如果设置了 border 属性,就设置这么宽的边框 属性样式的优先级低于 style,不影响在 style 里设置 border-colorborder-style,传入这样的 html 是有效的

<table style="border-width:1px;border-style:solid;border-color: red">
<td>1</td>
</table>

没有效果是怎么设置的

我这边遇到的情况是:后台管理使用TinyMce富文本编辑器编辑完后得到的html字符串是这样的

<table style="border-collapse: collapse; width: 100%; border-color: red; border-style: solid; margin-left: auto; margin-right: auto;" border="1" cellspacing="0">
<td>1</td>
</table>

使用该插件解析后得到的结果如下

nodes="[{"name":"table","attrs":{"style":"border:1px solid gray;border-collapse:collapse;width:100%;border-color:red;border-style:solid;margin-left:auto;margin-right:auto;border-spacing:0px","border":"1","cellspacing":"0"},

最终无论我在富文本编辑器中将表格边框设置为什么颜色在小程序里显示出来的永远都是border:1px solid gray;这个样式

不知道大家有没有遇到过这个情况

@jin-yufeng
Copy link
Owner

这个问题好像是这样的,border 属性除了给表格自身加边框,还会给内容的单元格加灰色边框
但是 style 里的 border-color 只会作用于 table 本身(关于这一点好像不同浏览器不太一样,谷歌浏览器是可以影响到内部单元格的,火狐不行,border 属性在标准里被废弃了)
1
QQ截图20220724164825
然后你看到的改不了颜色是因为设置合并了内外边框然后只显示了内部的灰色边框吧

@jin-yufeng
Copy link
Owner

你这样改的话就是让 style 里的 border-color 能够影响到单元格中因为 border 属性添加的边框颜色,这样好像是更合理一点,我再改回去吧

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants