【发布时间】:2020-10-22 07:39:09
【问题描述】:
我在 shadowDOM 自定义元素模板内应用表格样式,在插槽内,它不接受表格 th 和 td CSS。
class Table extends HTMLElement {
constructor() {
super();
// console.log("this accordion -> ", this)
setTimeout(() => {
const template = document.createElement('template');
template.innerHTML = `
<style>
::slotted(table) {
color: red;
width: 100%;
}
::slotted(table tr th),
::slotted(table tr td) {
text-align: left;
padding: 10px 0;
}
</style>
<slot></slot>
`;
const shadowDOM = this.attachShadow({
mode: 'open'
});
shadowDOM.appendChild(template.content.cloneNode(true));
}, 0);
}
}
customElements.define('t-table', Table);
<t-table>
<table>
<tr>
<th>Sl No.</th>
<th>Name</th>
</tr>
<tr>
<td>1</td>
<td>Name</td>
</tr>
</table>
</t-table>
上述场景如何应用CSS?
【问题讨论】:
标签: javascript css web-component tabular custom-element