Top: 0 work on absolutely-positioned elements relative to body - HTML CSS CSS Layout

HTML CSS examples for CSS Layout:Relative Position

Description

Top: 0 work on absolutely-positioned elements relative to body

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">
html {<!-- ww w .  j av  a  2s .  co  m-->
   background-color:Chartreuse;
}

h1 {
   margin:0;
}

body {
   position:relative;
   margin:0;
   padding:0;
   overflow:hidden;
   background-color:yellow;
}

.absolute {
   position:absolute;
   top:0;
   left:0;
   width:51px;
   height:51px;
   background-color:blue;
}

.wrapper {
   position:relative;
   overflow:hidden;
   width:51%;
   height:201px;
   overflow:hidden;
   background-color:pink;
}

.wrapper>.absolute {
   background-color:OrangeRed;
}
</style> 
 </head> 
 <body> 
  <div class="absolute"></div> 
  <h1>Lorem ipsu</h1> 
  <div class="wrapper"> 
   <div class="absolute"></div> 
   <h1>Lorem ipsu</h1> 
  </div>  
 </body>
</html>

Related Tutorials