Positioning with Top: -px - HTML CSS CSS Layout

HTML CSS examples for CSS Layout:Position

Description

Positioning with Top: -px

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
 </head> <!--from   ww w. ja  v  a  2  s  .  c  om-->
 <body> 
  <div id="div1" style="width: 1000px; height: 90px; background: red;"></div> 
  <div id="div2" style="position: relative; top:-50px; width: 1000px; height: 90px; background: blue;"></div> 
  <!--50 wasted pixels here--> 
  <div id="div3" style="width: 1000px; background: green; height:90px; margin-top: -50px;"></div>  
 </body>
</html>

Related Tutorials