#test1 { background: red; display: block; padding: 1em; margin: 1em; } #test1:empty { background: lime; } #test2 { background: lime; display: block; padding: 1em; margin: 1em; } #test2:empty { background: red; }