Ver Mensaje Individual
  #16 (permalink)  
Antiguo 06/06/2011, 09:40
kseso?
Colaborador
 
Fecha de Ingreso: junio-2007
Mensajes: 5.798
Antigüedad: 16 años, 10 meses
Puntos: 539
Respuesta: ¿ Como centrar varios DIV dentro de otro DIV ?

Otra forma más semántica pero menos compatible con pseudonavegadores
Código HTML:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es" lang="es-es">
  3. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2" />
  4. <style type="text/css">
  5. * {margin:0; padding:0; position: relative;}
  6. html, body {
  7.   height: 100%;
  8.   font-family: garamond, serif;
  9.   font-size: 100%;
  10. }
  11. #contenedor {
  12.   background: #fe0 url(serv/css/estilos/reticula.gif) repeat;
  13.   width: 900px;
  14.   margin: 0 auto;
  15.   overflow: hidden;
  16. }
  17. #contenedor > div {
  18.   width:140px;
  19.   height: 105px;
  20.   background: #cacaca;
  21.   float: left;
  22.   margin: 10px;
  23. }
  24. #contenedor > div:nth-child(3n) {
  25.   float:right;
  26. }
  27. #contenedor > div:nth-child(3n-1) {
  28.   margin-left: 220px;
  29.   margin-right: 220px;
  30. }
  31. </head>
  32.     <div id="contenedor">
  33.         <div>1</div>
  34.         <div>2</div>
  35.         <div>3</div>
  36.         <div>4</div>
  37.         <div>5</div>
  38.     </div>
  39. </body>
  40. </html>

Y si de centrar múltiples elementos (desconocido su número a priori) se trata, sin necesidad de crear cajas innecesarias sería con el uso de text-align: center; y letter-spacing (para separar los hijos lateralmente) en el contenedor padre y a los div´s hijos declararlos como elementos de línea.

Inieva: buena ocurrencia el crear la segunda caja de tamaño mayor.