Markus Pitha: <div> und vertikales zentrieren

Beitrag lesen

Hi,
Indem du alle Elternelemente auf 100% Höhe setzt. Wie soll sonst auch dein div wissen, was für dich die Mitte ist. Ich habe sogar stets ein fertiges Beispiel für so etwas, das du gerne anpassen kannst:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 Strict//EN"
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Style-Type" content="text/css" />
       <style type="text/css">
       <!--
       @import url("cssdata.css");
       -->
       </style>
<title>Box in der Mitte</title>
</head>
<body>
       <div class="box">&nbsp;</div>
</body>
</html>

-------------cssdata.css----------------
html {width:100%; height:100%;}
body {width:100%; height:100%;
margin:0;
padding:0;
background-color:black;
}
div.box {position:absolute;
top:50%; left:50%;
margin-top:-225px;
margin-left:-350px;
background-color:yellow;
width:700px; height:450px;
}

Markus.

--
sh:( fo:| ch:? rl:( br:> n4:( ie:{ mo:) va:) de:] zu:) fl:( ss:| ls:] js:|