puedo conseguir un div altura de 100%, así:CSS: ¿Es posible obtener un div que sea 100% alto, menos un margen superior e inferior?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>T5</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="stylesheet" type="text/css"
href="http://yui.yahooapis.com/3.0.0/build/cssreset/reset-min.css">
</link>
<style type="text/css">
* { padding: 0; margin: 0; }
html, body { height: 100%; }
body {
font-family: "lucida sans", verdana, arial, helvetica, sans-serif;
font-size: 75%;
}
h1 { font-weight: bold; font-size: 1.4em; padding: 10px 10px 0;}
p { padding: 0 10px 1em; }
#container {
min-height: 100%;
background-color: #DDD;
border-left: 2px solid #666;
border-right: 2px solid #666;
width: 280px;
margin: 0 auto;
}
* html #container { height: 100%; }
</style>
</head>
<body>
<div id="container">
<h1>100% Height Div</h1>
<p>Lorem ipsum ...</p>
</div>
</body>
</html>
Se ve así:
alt text http://i41.tinypic.com/1j1do8.jpg
Cuando digo "altura de 100%" - me refiero a que se mantenga la altura completa independientemente de la cantidad de contenido en el div, y sin importar cómo se redimensiona la ventana.
¿Pero es posible obtener un div con una altura de "casi el 100%" de altura? Si quiero márgenes en la parte superior e inferior, ¿puedo hacer eso?
quiero que se vea como esto:
alt text http://i44.tinypic.com/j76kvl.jpg
puedo hacer esto con CSS + Javascript. ¿Puedo hacerlo solo con CSS?
Respuesta:
Sí, es posible con el posicionamiento absoluto.
#container {
width: 380px;
background-color: #DDD;
border: 2px solid #666;
position: absolute;
top: 20px; /* margin from top */
bottom: 20px; /* margin from bottom */
left: 50%; /* start left side in middle of window */
margin-left: -190px; /* then, reverse indent */
overflow: auto; /* scrollbar as necessary */
}
Resultado:
alt text http://i42.tinypic.com/33vj3nq.jpg
Gracias to keithjgrant for the answer. Vea todo el código en http://jsbin.com/otobi.
¿No se puede hacer esto agregando _padding: 20px 0 20px 0; _ al estilo de id #container? – amelvin
No, porque el relleno y el margen se agregan al alto/ancho. Entonces esto haría una altura de 100% + 40px. – poke
necesita crear un contenedor interno dentro de su contenedor y luego agregar el relleno a ese – stephenmurdoch