3

Ive been looking around but have had no luck is it possible (with css) to target the body tag on input:focus so for example when someone clicks on the input box i want the body to have background:red, im not sure if this is actually possible.

Thanks in advance.

Connor

iConnor
  • 19,153
  • 13
  • 57
  • 91
  • Not possible without the use of javascript – Caelea Feb 13 '13 at 16:30
  • [CSS Selector Level 4](http://dev.w3.org/csswg/selectors4/#subject) supports this, but no browser has implemented it (it hasn't even been finalized yet). – Joseph Silber Feb 13 '13 at 16:32
  • What you're looking for is some kind of a parent selector. This question's answer should answer yours too: http://stackoverflow.com/a/1014958/262056 – Stephen Feb 13 '13 at 16:32

2 Answers2

4

This will be possible in the future with the CSS4 parent selector, but for now you would have to use JavaScript.

zakangelle
  • 4,830
  • 2
  • 18
  • 28
2

This is not possible with CSS. But it can be easily achieved with javascript / jQuery :)

This is how to do it in jQuery,

$("input[type=text]").focus(function() {
    $("body").css({"background-color" : "red"});
});
Sandeep Raju Prabhakar
  • 14,834
  • 7
  • 33
  • 42