Kompx.com or Compmiscellanea.com

HTML centering

Windows : Internet Explorer 3.0+, Firefox 1.0+, Google Chrome, Opera 3.51 - 6.xx and 9.0+, Safari 3.1+, SeaMonkey 1.0+ [ 1 ].

Linux : Firefox 1.0+, Chromium, Opera 5.0 - 6.xx and 9.0+, SeaMonkey 1.0+ [ 2 ].

Centering the whole content of a web page in the viewable area of a browser by pure HTML - no CSS. A box to keep the content of the page is HTML centered horizontally and vertically - [ Open demo page ]

HTML. Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<title>HTML centering</title>

<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">

</head>

<body bgcolor="#ffffff">

<table width="100%" height="100%" bgcolor="#a3ddc4">

<tr>

<td align="center">

<table width="800" height="500" bgcolor="#ff6f6f">

<tr>

<td>&nbsp;</td>

</tr>

</table>

</td>

</tr>

</table>

</body>

</html>

The outer HTML table makes the whole web browser viewable area, except margins, a HTML table and the whole area of this HTML table - a HTML table cell.

The cell of the outer HTML table inherits the default value for valign attribute from its parent table row. And this row in its turn inherits the default value for valign attribute from the outer HTML table tbody - even if tbody tag is not used. And that value is middle. So a block of content inside the cell of the outer HTML table is centered vertically in web browser viewable are.

Align="center" of the outer HTML table cell makes a block of content inside it centered horizontally in web browser viewable are.

The inner table, the one inside of the outer HTML table cell makes up a box of a given size. Or there may be no set height or no set width or both. Then the size of the box is to adjust to accommodate the content, whatever its dimensions are. If the width or height or both of the box results to be larger than web browser viewable area, then it still ends up to be centered.

Since HTML centering is the oldest method to center content horizontally and vertically, it works well not just in older web browsers, but in ones that can be described as downright ancient. Like adding one more HTML tag ( <center></center> ) around the outer table makes it funcion as deep as Internet Explorer 3 : [ Open demo page ]

Download Internet Explorer 3: a pack, containing 3.0, 4.01, 5.01, 5.5, 6.0 versions of Internet Explorer

HTML. Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<title>HTML centering for Internet Explorer 3</title>

<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">

</head>

<body bgcolor="#ffffff">

<!-- For Internet Explorer 3 --><center><!-- For Internet Explorer 3 -->

<table width="100%" height="100%" bgcolor="#a3ddc4">

<tr>

<td align="center">

<table width="800" height="500" bgcolor="#ff6f6f">

<tr>

<td>&nbsp;</td>

</tr>

</table>

</td>

</tr>

</table>

<!-- For Internet Explorer 3 --><center><!-- For Internet Explorer 3 -->

</body>

</html>

HTML horizontal and vertical centering of a box containing web page content has become obsolescent as a result of semantic markup spread. But it is still reliable. Not only in the major and modern web browsers, but in many alternative and older ones as well.

There is a minor flaw in it though. The height attribute of the <table><table/> tag is used there. It is supported for years by the majority of web browsers, but is incompatible with the standards promoted by World Wide Web Consortium (W3C). So the code does not pass W3C validation. Back in 1990s - early 2000s, it was complicated or impossible to succeed in making a code both valid and working in the majority of web browsers, so the flaw was not looked at as a real problem.


[ 1 ]

As well as Netscape 2.02 - 4.80 and Offbyone. There is some shift of page content to the top left corner of the web browser viewable area in Netscape 2.02 - 4.80, since these web browsers reserve the place for scrollbars.

[ 2 ]

As well as Netscape 2.02 - 4.80. There is some shift of page content to the top left corner of the web browser viewable area in Netscape 2.02 - 4.80, since these web browsers reserve the place for scrollbars.


Aliosque subditos et thema


CSS centering image


CSS horizontal centering of an image. Example: HTML / XHTML. Code: <div class="example"> <img src="image.jpg" alt="Image" /> </div> CSS. Code: .example {position: relative; left: 0px; top: 0px; height: auto; width: 100%; float: left; padding: 10px; border: 1px #ccc solid; background: #fafafa;} .example img {display: block; margin: 0 auto;} CSS properties of a container (here it is example) may vary, image centering is achieved by styles applied to the image itself: .example img {display: block; margin: 0 auto;}. [ 1 ] As well as Opera 4.0+, if shorthand CSS is not used in styles. That is, if it is .example img {display: block; margin-left: auto; margin-right: auto;}. [ 2 ] As well as Netscape 6.01+, Mozilla 0.6+. [ 3 ] As well as Netscape 6.01+, Mozilla 0.6+.

HTTP to HTTPS redirect in .htaccess


Redirecting from all domain names of a web site to its web address with HTTPS and the domain with www. The names to be redirected from are: Both with and without www - URL with HTTP Without www - URL with HTTPS Server configuration: Apache + nginx. SSL in enabled. SSL-certificate is purchased, approved and installed. That is, everything is up and running. So it is just the HTTP to HTTPS redirection that is left to get ready and start up. Directives for .htaccess file: RewriteEngine On RewriteCond %{HTTP:HTTPS} !on [NV] RewriteRule ^(.*)$ https://www.domain.tld/$1 [R=301,L] RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ https://www.domain.tld/$1 [R=301,L] HTTP to HTTPS redirect in detail RewriteEngine On -- Enable runtime rewriting engine RewriteCond %{HTTP:HTTPS} !on [NV] -- If HTTPS is not present RewriteRule ^(.*)$ https://www.domain.tld/$1 [R=301,L] -- Then replace HTTP + domain (with or without www) with HTTPS + domain with www RewriteCond %{HTTP_HOST} !^www\. -- If HTTPS is present, but domain name has no www (the case when https://domain.tld is entered in address bar) RewriteRule ^(.*)$ https://www.domain.tld/$1 [R=301,L] -- Then replace it with HTTPS + domain with www. Apache Module mod_rewrite docs: http://httpd.apache.org/docs/current/mod/mod_rewrite.html