简体   繁体   English

如何选择带槽元素的内容?

[英]How do I select content of a slotted element?

I have a span in my slot.我的插槽中有一个跨度。 And that slot contains div>ul>li.该插槽包含 div>ul>li。 I would like to have access to the ul element.我想访问 ul 元素。

My code:我的代码:

<slot>
    <span>
        <div>
            <ul>
                <li>Test</li>
                <li>Test123</li>
                <li>Testabc</li>
            </ul>
        </div>
    </span>    
</slot>

I have tried something like this, but it didn't work:我试过这样的事情,但没有奏效:

 ::slotted(span[ul]) {
        background-color: rgba(255, 55, 255, 1);
        border: brown;
    }

Why complicate things when you can do this -当你能做到这一点时,为什么要把事情复杂化——

 slot span ul { background-color: rgba(255, 55, 255, 1); /* border: brown; */ /* this is not valid */ border: 1px solid brown; }
 <slot> <span> <div> <ul> <li>Test</li> <li>Test123</li> <li>Testabc</li> </ul> </div> </span> </slot>

To select an ul in a span in a slot you can just use slot span ul { ... } :要在slot中的span中选择ul ,您只需使用slot span ul { ... }

 slot span ul { background-color: rgba(255, 55, 255, 1); border: solid brown 3px; }
 <slot> <span> <div> <ul> <li>Test</li> <li>Test123</li> <li>Testabc</li> </ul> </div> </span> </slot>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM