【发布时间】:2020-07-10 21:17:33
【问题描述】:
这是我的尝试,但 span 元素没有我希望的 deeppink 边框(我在 Google Chrome 83 中):
const d = document.querySelector('div')
const r = d.attachShadow({mode: 'open'})
r.innerHTML = `
<style>
/* This doesn't work as I was hoping: */
::slotted(p) span {
border: 1px solid deeppink;
}
/* This doesn't work (and I wouldn't expect it to), but I tried it anyways: */
::slotted(span) {
border: 1px solid deeppink;
}
/* This doesn't work either: */
:host span {
border: 1px solid deeppink;
}
/* This works, but not what I'm trying to do. */
::slotted(p) {
background: #f9f9f9
}
</style>
<slot></slot>
`
<div>
<p><span>test</span></p>
<p><span>test</span></p>
<p><span>test</span></p>
<p><span>test</span></p>
<p><span>test</span></p>
</div>
我们如何为分布式(开槽)子代的后代设置样式?
【问题讨论】:
标签: javascript html css shadow-dom