HTML Element Style How to - Hover to reveal new div








Question

We would like to know how to hover to reveal new div.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.container {<!--  w  w  w .j a v a 2  s. c  o  m-->
  overflow: hidden;
  height: 60px;
}

.one {
  position: relative;
  top: 0;
  background-color: lightblue;
  z-index: 1;
}

.two {
  position: relative;
  top: -40px;
  background-color: yellow;
  z-index: -1;
  -webkit-transition: top 1s;
  -moz-transition: top 1s;
  -o-transition: top 1s;
  transition: top 1s;
}

.one:hover+.two {
  top: 0px;
}
</style>
</head>
<body>
  <div class="container">
    <div class="one">Hover me to reveal new div</div>
    <div class="two">
      This is <br>a test...
    </div>
  </div>
</body>
</html>

The code above is rendered as follows: