<div class="wrapper">
<h1>Title</h1>
<div class="content">
<p>child 1</p>
</div>
</div>
/* CSS solution */
.wrapper:has(.content:not(:empty)) {
background-color: tomato;
}
.wrapper:has(.content:empty) {
display: none;
}
/** JS solution */
// const wrapperDiv = document.querySelector('.wrapper')
// const contentDiv = wrapperDiv.querySelector('.content')
// if (contentDiv.childNodes.length > 0) { wrapperDiv.style.backgroundColor = 'tomato'
// } else {
// wrapperDiv.style.display = 'none'
// }
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.