0

Is there a way to write css so it would select a div above a selector you already known. For example.

#modal .container .login{
 //style
}

so the above code will look for an ID of modal > classname of container > classname of login. And style the .login. Now is is possible to have it go the reverse. So style the #modal only if it has a child of .login and .container

Thanks

Chapsterj
  • 6,483
  • 20
  • 70
  • 124

1 Answers1

0

Short answer? no. (in the current CSS spec) as already answered here. Is there a CSS parent selector?

but, I can give you a little trick.

create a special CSS rule (a class) with your special styling for the 'parent'.

then, with JQuery, on document.ready, check for all the elements in the DOM who meets your requirement (in your case: has a child of some class), and dynamically add the special CSS class.

It's not a perfect solution, but can be helpful in some cases.

Community
  • 1
  • 1
avrahamcool
  • 13,888
  • 5
  • 47
  • 58
  • Very good trick but what if the element is invisible and only has the child when a user clicks something else to load the element. – Chapsterj Sep 19 '13 at 19:34
  • In the case of dynamic data, more thinking will be needed. but eventually all things can be sorted out and solved. something like: the code who adds the dynamic data also run a check for the dynamic styling. – avrahamcool Sep 19 '13 at 19:38