3

So I can't seem to find a way to hide a parent element based on a certain circumstance. I have two sections of code that work individually but can't figure out how to combine them. So here is the element I am working with:

<div id="grid_content">
<img src="img/test_0000.jpg" class="staticimg">
</div>

I need the 'div' to hide when the image source is empty. I can make the 'img' itself hide when empty (src="") using the CSS:

img[src=""] {display: none;}

And also I can make the div hide if empty using the CSS:

#grid_content:empty {display: none;}

So, the question is how can I make '#grid_content' hide when the image 'src' is empty?

Dan
  • 39
  • 1
  • can you use jQuery? – Roysh Jun 13 '16 at 08:22
  • 1
    One of the most inflexible rules of CSS is about parent selectors...wait...for...it...It doesn't exist. When referencing any selector relationship with another, it is going to be either a direct reference to the element, a reference to an element's descendant or an element's siblings. You'll never be able to affect an element's styles by it's influence of it's children. – zer00ne Jun 13 '16 at 08:27
  • Since the source is sometimes empty and sometimes not, I guess you're using a server side language (like php). Why don't you check there if the source is empty and show than the div or not. – user3528269 Jun 13 '16 at 08:30
  • @Dan I found a solution to your particular problem, unfortunately your question is on hold because of it's similarities with http://stackoverflow.com/questions/1014861/is-there-a-css-parent-selector ... I'll give you an answer there so it can be buried like like the Arc in a government warehouse... -_- – zer00ne Jun 13 '16 at 09:06
  • Ok, here's my 2 cents on [parent selector](http://stackoverflow.com/a/37785933/2813224). if it helps (which it definitely should), upvote my answer there. – zer00ne Jun 13 '16 at 09:19
  • There is a CSS extension called EQCSS that has a bunch of different meta-selectors, and a parent selector is one of them. Check it out at http://elementqueries.com/#parent-selector or view a demo of it [here](http://elementqueries.com/demos/parent.html) – innovati Jun 13 '16 at 14:09
  • Hey Dan, I'm deleting the answer, because the question that's considered the same as yours requires a different answer. So if you want a solution reword your question so you won't get it closed. – zer00ne Jun 13 '16 at 14:34

0 Answers0