henrywright
henrywright

Reputation: 10240

How to style parent element if child element is empty?

Is there a way to style a parent element if the child element is empty? For example:

Here, the <li> element is empty so I'd like the ul element to be styled with padding: 20px:

<ul class="list">
    <li></li>
</ul>

Upvotes: 0

Views: 1445

Answers (1)

enguerranws
enguerranws

Reputation: 8233

You can't target a parent element with CSS. So it seems impossible to achieve this only with CSS.

Assuming you're using jQuery :

$('.list li:first-child').is(':empty').parent().css({"padding-top", "20px"});

Upvotes: 2

Related Questions