是否有用于派生HTML自定义元素的CSS选择器?

问题描述 投票:0回答:1

说有一个以典型方式定义的自定义HTML元素,另一个是从其继承的:

class CEParent extends HTMLElement { constructor() { super(); } }
class CEChild  extends CEParent    { constructor() { super(); } }
customElements.define("ce-parent", CEParent);
customElements.define("ce-child",  CEChild);

现在假定HTML仅包含对<ce-child></ce-child>元素的引用。是否可以根据<ce-child>选择/设置ce-parent的样式?

ce-parent:and-derived-too {
    ...
}

css-selectors custom-element
1个回答
0
投票

这会将父元素名称分配为每个元素的CSS类

需要一些字符串处理,因为对于匿名函数,constructor.name为“”(空字符串)

© www.soinside.com 2019 - 2024. All rights reserved.