【发布时间】:2019-04-04 15:13:18
【问题描述】:
我正在使用 lit-element 制作自定义元素。我想制作自己的自定义表格元素,但是有一些问题。
首先。似乎浏览器只允许tr、td 标签用于table。
<!-- in html -->
<my-table>
<tr>
<td>A</td>
<td>B</td>
</tr>
</my-table>
<!-- chrome rendered -->
<my-table> A B </my-table>
第二。可以用CSS模仿,但是CSS不能实现colspan。
<my-table> <!-- display: table -->
<my-tr> <!-- display: table-row -->
<my-td>A</my-td> <!-- display: table-cell -->
<my-td colspan="3">B</my-td> <!-- There is no way to implement colspan -->
</my-tr>
</my-table>
第三。我尝试在主机上使用“显示:内容”进行样式设置。这似乎可行,但主机没有像 clientHeight 这样的框大小数据。
class MyTd extends LitElement {
render() {
return html`
<style>
:host { display: content; }
td {
all: inherit; /* It make to inherit host's style */
display: table-cell;
}
</style>
<td>
${html`<slot></slot>`} // I don't know why it work.
</td>
`;
}
}
// other js file.
const td = document.querySelector('my-td');
td.clientHeight; // 0
我可以覆盖 clientHeight 和其他东西(offsetHeight、getBoundingClientRect...),但我不知道这是正确的,这是唯一的方法。
还有其他方法可以创建自定义表格还是我的想法有问题?
【问题讨论】:
-
可以使用css column-count: 3;作为 colspan 的替代品。
-
你应该看看这个问题:stackoverflow.com/q/41585527/4600982
标签: html css polymer custom-element lit-element