Is there a way to show or hide a div conditionally based on the content of another div, using only CSS? I want to avoid using JavaScript.
In the past, I've used a workaround like this:
.myClass:empty:before {
content: 'content added to empty div';
}
- This method works for adding content to an empty div. However, it doesn't support creating hyperlinks in the generated pseudo-content. That's why I'm exploring other options.
Let's say my current div structure looks like this:
<div class="div1"></div>
<div class="div2">This should be displayed</div>
Is there a CSS technique that can display div2 if div1 is empty, but hide it if div1 has any content?
Feel free to suggest alternative ways to organize the div elements, as long as they achieve the desired outcome regardless of the current structure.
I'm open to ideas and suggestions. Thank you.