Effect How to - Target CSS With Grandparents








Question

We would like to know how to target CSS With Grandparents.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.grandParent {<!--from   w w w.j  a  va2 s  .com-->
  padding: 20px;
  background: red;
  position: relative;
}

.secondChild:hover+.child {
  background: pink !important;
}

.child {
  padding: 20px;
  background: green;
}

.secondChild {
  position: absolute;
  top: 100%;
  padding: 20px;
  background: grey;
}
</style>
</head>
<body>
  <div class="grandParent">
    <textarea class="secondChild"></textarea>
    <div class="child"></div>
  </div>
</body>
</html>

The code above is rendered as follows: