If I have two DIVs where I apply CSS using :empty
so that if one DIV has content, then the other's background will change color, it works if the DIVs aren't nested. In the fiddle, type anything into the top white box, the other will turn yellow.
http://jsfiddle.net/7fwL26ox/7/
<div id="inner-div" contenteditable=true></div>
<div id="outer-container">
</div>
#outer-container {
padding: 2em 0;
background-color: #CCC;
}
#inner-div{
border: 1px solid #000;
}
#inner-div:not(:empty) + #outer-container{
background-color: yellow;
}
If I nest the DIVs, where the DIV that is empty and changes content, is nested inside the DIV that changes color, it no longer works (input is outlined in the fiddle).
http://jsfiddle.net/vpcwtg7m/1/
<div id="outer-container">
<div id="inner-div" contenteditable=true></div>
</div>
#outer-container {
padding: 2em 0;
background-color: #CCC;
}
#inner-div{
border: 1px solid #000;
}
#inner-div:not(:empty) + #outer-container{
background-color: yellow;
}
I would have expected in the second fiddle, that the background will also change to yellow. Exact same CSS, just the placement of the DIVs has changed. Cheers!