Welcome to WebmasterWorld Guest from 18.104.22.168
Forum Moderators: incrediBILL
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<table cellpadding="0" cellspacing="0" border="0" width="100%" height="100%">
<td width="100%" align="center">This text is centered on the screen</td>
Note that the above requires quirks mode in the browser and doesn't validate so you should not add a doctype. This method is perfect for a quick-and-dirty one-page implementation.
The second method is to use CSS:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="content-type" content="text/html;charset=UTF-8">
border:1px solid black;
This text box is centered on the screen
This method centers a box (not an arbitrary piece of text) both horizontally and vertically. The basic idea is to have an outer container placed at 50% from the top with a 1px nominal height, and an inner container with a fixed height in pixels, a negative top position representing half of the declared height, and a negative left margin representing half of the declared width.
The CSS version is better when you have a more complex layout dependent on standards mode, but you may still need to use a table within the inner box - unfortunately as the difference between the two methods shows, vertical centering within the viewport is one of the weak points with CSS designs.