000 001 002 003 004 005 006
* { position: absolute; top: 20%; height: 60%; // 60% + 20% superior + 20% derecha = 100% left: 20%; width: 60%; // 60% + 20% + 20% = 100% }
X - ( ancho contenedor / 2 ) - ( ancho objeto / 2 ) Y - ( alto contenedor / 2 ) - ( alto objeto / 2 )
000 001 002 003 004
* { position: absolute; left: 50%; top: 50%; }
000 001 002 003 004 005 006 007 008
* { position: absolute; left: 50%; top: 50%; height: 200px; margin-top: -100px; // 200px/2 width: 300px; margin-left: -150px; // 300px/2 }
000 001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"> <head> <style> div { position: absolute; left: 50%; top: 50%; width: 300px; height: 200px; margin-top: -100px; margin-left: -150px; overflow: auto; border: 1px solid red; } </style> </head> <body> <div> Este es el DIV centrado <br /> Este es el DIV centrado <br /> Este es el DIV centrado <br /> Este es el DIV centrado <br /> Este es el DIV centrado <br /> Este es el DIV centrado <br /> Este es el DIV centrado <br /> Este es el DIV centrado <br /> Este es el DIV centrado <br /> Este es el DIV centrado <br /> Este es el DIV centrado <br /> Este es el DIV centrado <br /> Este es el DIV centrado <br /> Este es el DIV centrado <br /> Este es el DIV centrado <br /> Este es el DIV centrado <br /> Este es el DIV centrado <br /> Este es el DIV centrado <br /> Este es el DIV centrado <br /> Este es el DIV centrado <br /> Este es el DIV centrado </div> </body></html>