How do I select the first adjacent sibling?

前端 未结 8 2161
北海茫月
北海茫月 2020-12-30 19:38

I have an HTML list like so:

  • Heading 1
8条回答
  •  时光说笑
    2020-12-30 20:25

    It is not possible using CSS as currently defined and implemented. It would require a selector that selects an element on the basis of its siblings after it. CSS selectors can select an element on the basis of preceeding or outer elements, but not on the basis of following or inner elements.

    The desired effect can be achieved using JavaScript in a rather straightforward way, and you can decide, depending on the purpose, whether you just remove the elements from display or completely remove them from the document tree.

提交回复
热议问题