CSS Layout How to - offset original position








Question

We would like to know how to offset original position.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
p {<!--from  w  ww .  j a  v a2  s.c  om-->
  background: #eee;
  margin: 30px 0;
}

.offset {
  position: relative;
  top: -20px;
  left: 20px;
  background: #ffe;
}
</style>
</head>
<body>
  <p>this paragraph is static</p>
  <p class="offset">this paragraph is offset</p>
  <p>this paragraph is static</p>
</body>
</html>

The code above is rendered as follows: