CSS Layout How to - DIV absolute positioning - maintain position after browser window resize








Question

We would like to know how to dIV absolute positioning - maintain position after browser window resize.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.parent {<!--from  w w  w  . ja  v  a  2 s. c  o  m-->
  width: 200px;
  height: 200px;
  border: 1px solid red;
  position: relative;
}

.child {
  width: 100px;
  height: 100px;
  background: blue;
  position: absolute;
  top: 0;
  right: 0;
}
</style>
</head>
<body>
  <div class="parent">
    <div class="child"></div>
  </div>
</body>
</html>

The code above is rendered as follows: