I'm trying to figure out what's the deal with combining pseudo-elements with the ::slotted
selector, looks like it works with some but not with others and I can't find any documentation listing the selectors it works with
Here is a demonstration of the problem, notice how some pseudo-selectors take effect while others don't
class TestElement extends HTMLElement {
constructor() {
super();
this.attachShadow({mode: 'open'});
let template = document.querySelector("template");
this.shadowRoot.append(template.content.cloneNode(true));
}
}
customElements.define("test-element", TestElement);
<template>
<style>
::slotted(*)::first-line { /* doesn't works */
color: red;
}
::slotted(*):first-letter { /* doesn't works */
color: red;
}
::slotted(*) {
max-height: 3em;
overflow: auto;
}
::slotted(*)::-webkit-scrollbar { /* doesn't works */
width: 3px;
}
::slotted(*)::-webkit-scrollbar-track { /* doesn't works */
background-color: red;
}
::slotted(*)::selection { /* doesn't works */
color: red;
}
::slotted(*)::placeholder { /* works */
color: red;
}
::slotted(*)::marker { /* works */
color: red;
}
</style>
<slot></slot>
</template>
<test-element>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Sapiente
doloribus ullam fugit ipsum laborum velit architecto, provident dolore
at, aperiam quaerat officiis aliquid magni sed expedita totam dolor
doloremque odit.
Lorem ipsum dolor sit amet consectetur adipisicing elit. Sapiente
doloribus ullam fugit ipsum laborum velit architecto, provident dolore
at, aperiam quaerat officiis aliquid magni sed expedita totam dolor
doloremque odit.
Lorem ipsum dolor sit amet consectetur adipisicing elit. Sapiente
doloribus ullam fugit ipsum laborum velit architecto, provident dolore
at, aperiam quaerat officiis aliquid magni sed expedita totam dolor
doloremque odit.</p>
</test-element>
<test-element>
<input placeholder="Placeholder">
</test-element>
<test-element>
<li>Li</li>
</test-element>
first-letter
is not an element - it's a pseudo reference to text. – Allopathy<p>
), not that the selector can't select text within the element, but I might be wrong. But regardless, even if you're right, it would only explainfirst-letter
andfirst-line
not the others likeselection
andwebkit-scrollbar
. – Glosseme::selection
andwebkit-scrollbar
I wonder if it's because they aren't necessarily part of the actual shadow dom - and::selection
still refers to the actual text and not a basic/simple selector. – Allopathy