'position: static;' vs 'position: relative;' child element is absolutely positioned - HTML CSS CSS Layout

HTML CSS examples for CSS Layout:Relative Position

Description

'position: static;' vs 'position: relative;' child element is absolutely positioned

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <style id="compiled-css" type="text/css">
.child {<!--from   w  w  w .j  a v a2  s. c o m-->
   position:absolute;
   height:100px;
   width:100px;
   border:2px solid Chartreuse;
   left:201px;
}

.child2 {
   position:absolute;
   height:100px;
   width:100px;
   border:2px solid yellow;
   left:100px;
}

.parent {
   position:relative;
   left:11px;
   right:11px;
   border:2px solid blue;
   width:51px;
   height:51px;
}

.parent2 {
   border:2px solid pink;
   width:51px;
   height:51px;
}
</style> 
 </head> 
 <body> 
  <div class="parent"> 
   <div class="child"> 
   </div> 
  </div> 
  <div class="parent2"> 
   <div class="child2"> 
   </div> 
  </div>  
 </body>
</html>

Related Tutorials