Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
  <div class="relative2">
    <p>position: relative.</p>
    <p>position: relative does 3 things:</p>
  <ol>
    <li>enables top/left/bottom/right</li>
    <li>enables z-index</li>
    <li>descendant with position: absolute; is positioned relative to nearest position: relative; ancestor</li>
  </ol>
    <div class="posAbsolute">Absolutely positioned relative to ancestor</div>
  </div>
    <p><a href="http://learnlayout.com/position.html">source</a></p>
</body>
</html>
 
body, p {
  margin: 0;
  padding: 0;
}
.posAbsolute {
  background-color: green;
  width: 150px;
  height: 50px;
  position: absolute;
}
.relative2 {
  position: relative;
  border: 2px dotted #eee;
  height: 200px;
  top: 30px;  
  left: 60px;
  width: 80%;
  background-color: orange;
}
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers