position a div in the absolute center of a page - HTML CSS CSS Layout

HTML CSS examples for CSS Layout:Absolute Position

Description

position a div in the absolute center of a page

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">
body {<!--  w  w  w  .  j a va 2s  . co  m-->
   height:10001px;
}

#myDiv {
   background:red;
   width:100px;
   height:100px;
   margin-top:-51px;
   margin-left:-51px;
   position:fixed;
   top:51%;
   left:51%;
}
</style> 
 </head> 
 <body> 
  <div id="myDiv"></div>  
 </body>
</html>

Related Tutorials