Animation How to - Hover to overlap divs








Question

We would like to know how to hover to overlap divs.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.div-1, .div-2 {<!--from   w  ww.ja  va2s  . co  m-->
  cursor: pointer;
  height: 160px;
  width: 300px;
  position: absolute;
  padding: 10px;
  text-align: right;
  font-family: "Gill Sans", sans-serif;
}

.div-1 {
  border: 3px solid #7f7f7f;
  color: #7f7f7f;
  top: 20px;
  left: 60px;
  z-index: 1;
}

.div-1:hover {
  color: #19b1cd;
  border-color: #19b1cd;
}

.div-2 {
  background-color: #b4dde5;
  color: #779396;
  top: 60px;
  left: 20px;
  z-index: 0;
}

.div-2:hover {
  background-color: #19b1cd;
  color: #fff;
}
</style>
</head>
<body>
  <div class="div-1">(div-1)</div>
  <div class="div-2">HOVER HERE (div-2)</div>
</body>
</html>

The code above is rendered as follows: