0

Every thing is possible by CSS3, then how I do this by CSS?

(1)

<h2> Top Test Text </h2>
<h2> Test Text <span class="a"></span> </h2>

Apply color: red to only parent h2 of class="a" not to top h2, with out adding <h2 style"color: red"> of with out adding class There have any CSS Selectors to do that? I Mean, Parent h2 will red color if .a class is present on the page.

(2)

<div class="a"> Test Text </div>
<div class="b"></div>

Apply color: red to only .a if .b class is present on the page.

Matt
  • 13,445
  • 23
  • 82
  • 120
Sini Roxy
  • 1
  • 1
  • 1

1 Answers1

0

As commented: CSS cannot do this.


To answer at your comment:

In jQuery for the first example it would be:

$( "h2" ).has( "span.a" ).css( "color", "red" );

For both sub question , In jQuery you can use has() Demo: http://codepen.io/anon/pen/VYGrBv

G-Cyrillus
  • 85,910
  • 13
  • 85
  • 110