CSS Layout How to - Compare Relative positioning with original position








Question

We would like to know how to compare Relative positioning with original position.

Answer


<!DOCTYPE html>
<html>
<head>
<style type='text/css'>
.positioned {<!--from  ww  w . j a v  a 2 s . c  o  m-->
  position: relative;
  left: 10px;
  top: 15px;
}
body {
  padding: 10px;
}

p {
  margin: 1em 0 2em 0;
}

div {
  background: #fafafa;
  border: 1px solid #777;
  padding: 5px;
}

.container {
  border: 1px dashed #000;
  margin: 0;
  padding: 0;
}

.positioned {
  background: #e1eef5;
}
</style>
</head>
<body>
  <p>The gray box is where the blue box would be if it weren't
    positioned.</p>
  <div class="container">
    <div class="positioned">relative; left: 10px; top: 15px;</div>
  </div>
</body>
</html>

The code above is rendered as follows: