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
  • 62,582
  • 13
  • 151
  • 162
nha
  • 16,039
  • 11
  • 76
  • 108

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,841
  • 1
  • 22
  • 32