Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
<html>
<head>
<script language="javascript">
window.onload = function() {vCenter();}
function vCenter() {
var winHeight = document.getElementsByTagName('body')[0].clientHeight;
var contentHeight = 300;
var vCenterLoc = (winHeight - contentHeight) / 2;
var contentBlock = document.getElementById("content");
contentBlock.style.marginTop
= (contentHeight < winHeight)
? vCenterLoc
: 0;
}
</script>
<style>
body {
margin: 0 auto;
text-align:center;
}
#content {
border: 1px solid #000000;
padding: 3px;
width: 500px;
height: 300px;
margin: 0 auto;
text-align: left;
}
</style>
</head>
<body onResize="vCenter();">
<div id="content">
<p><strong>Lorem ipsum</strong> <a href="[URL unfurl="true"]http://www.lipsum.com"[/URL] target="_blank">what's this?</a></p>
<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean nibh. Donec malesuada. Donec neque. Sed elit ligula, venenatis ac, vehicula et, pulvinar ut, orci. Sed sagittis, lectus sed sodales rhoncus, quam leo sodales mi, sit amet pulvinar eros magna sed ipsum. Sed non metus.</p>
</div>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd">[/URL]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>CSS vertical center using float and clear</title>
<style type="text/css">
* {
margin:0;
padding:0;
}
html, body {
height:100%;
}
body {
background-color:#fc6;
color:#630;
font:100.01%/1.4 sans-serif;
text-align:center; /* horizontal centering for IE Win quirks */
}
#distance {
width:1px;
height:50%;
background-color:#fc6;
margin-bottom:-13.75em; /* half of container's height */
float:left;
}
#container {
margin:0 auto;
position:relative; /* puts container in front of distance */
text-align:left;
height:27.5em;
width:45em;
clear:left;
background-color:#ff9;
border:1px solid #c93;
border-top-color:#fff;
border-left-color:#fff;
}
#container div {
font-size:80%;
float:right;
width:17em;
margin-left:2em;
}
#container div h2 {
font-size:120%;
font-weight:bold;
text-transform:uppercase;
margin:1em 0 0;
}
#container div h3 {
font-size:100%;
font-weight:bold;
margin:.5em 0 0 .75em;
}
#container ul {
margin-left:2em;
}
#container li span {
font-size:70%;
}
#container h1 {
font-size:120%;
padding-top:2.4em;
margin-left:2.4em;
}
#container p {
margin:1.5em 13.6em 1.5em 3em;
}
address {
font-weight:normal;
font-size:80%;
font-style:normal;
text-align:right;
margin:0 20em 0 3em;
}
</style>
</head>
<body>
<div id="distance"></div>
<div id="container">
<div>
<h2>Tested in</h2>
<h3>Win XP SP1</h3>
<ul>
<li>Firefox 1.04</li>
<li>Opera 6.06 / 7.23 / 8.0</li>
<li>Netscape 6.1 / 7.1</li>
<li>IE 5.0 / 5.5 / 6</li>
</ul>
<h3>Mac OS9</h3>
<ul>
<li>Mozilla 1.2.1</li>
<li>Netscape 7</li>
<li>IE 5</li>
<li>WaMCom <span>[thx T. Jung]</span></li>
<li>iCab 3.0 Beta 340 <span>[thx T. Jung]</span></li>
</ul>
<h3>Mac OSX</h3>
<ul>
<li>Safari 1.0.3 / 1.3</li>
<li>Firefox 1.0.4</li>
<li>Netscape 7</li>
<li>Opera 6</li>
<li>Camino</li>
<li>IE 5</li>
</ul>
</div>
<h1>CSS vertical centering using float and clear - crossbrowser (?)</h1>
<p>
This box stays in the middle of the browser's viewport.<br>
The content does not disappear when the viewport gets smaller than the box.
</p>
<p>
It even works in IE5 Mac - the doctype triggers this browser to quirks-mode and the IEMac-only stylesheet kills the height for html, body.
</p>
<address>fricca[at]uk2.net | 07.08.05</address>
</div>
</body>
</html>
BRPC said:And they don't consider this to be a forum?