0

Is it possible in pure css to change the background-color of the body element depending of the id (or class) of the first div inside the body ?

For instance :

<body> 
  // background-color is black
  <div id="abc"> ... </div>
</body>


<body> 
  // background-color is red
  <div id="cde"> ... </div>
</body>
cimmanon
  • 67,211
  • 17
  • 165
  • 171
nha
  • 17,623
  • 13
  • 87
  • 133

1 Answers1

1

No there's no way of doing this purely in CSS. You'll need to your javascript/jquery for that, which will change your body background for it.

if ($('#abc')[0]) {
   $('body').css('background','black')
}
if ($('#cde')[0]) {
   $('body').css('background','red')
}
Joe Saad
  • 1,940
  • 3
  • 22
  • 32