Can I use CSS to apply styles based on child element count?

前端 未结 1 1432
独厮守ぢ
独厮守ぢ 2021-01-24 13:14

I have a situation where n elements can be present and any can be deleted. But at the point where only one element is present, the deletion should be disabled (ideally

相关标签:
1条回答
  • 2021-01-24 13:53

    You can't specify it on the parent (DIV.items), but you can on the child (DIV.item) with the :only-child pseudo-class. Since you're styling a descendant of the child here, what you're looking to do is in fact possible:

    DIV.item:only-child BUTTON.delete {
        display: none;
    }
    
    0 讨论(0)
提交回复
热议问题