Page Widget How to - Position text absolute to parent box








Question

We would like to know how to position text absolute to parent box.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.box {<!--from  ww w  .ja va2  s.co m-->
  position: relative;
  border: 1px solid #EEE;
  float: left;
}

.box div {
  position: absolute;
  top: 0;
  left: 100%;
  border-color: #AAA;
  border-style: solid;
  border-width: 1px;
  width: 80px;
  height: 80px;
  text-align: center;
  display: inline-box;
}
</style>
</head>
<body>
  <div class="box">
    Hello World
    <div>BOX</div>
  </div>
</body>
</html>

The code above is rendered as follows: