开发者

Is it a good idea to align to center a site with CSS like this?

I have seen a tutorial on youtube which centers a site by giving margin: 0px auto; and by saying the actual width of the site:

body 
{
    align:center;
    margin: 0px auto;
    width: 1000px;
}

But this does not work for ie8. IS this a good idea to use in order to align to center the l开发者_开发技巧ayout?


It works in IE6 and newer providing the browser is in standards mode. Trigger it with a Doctype such as:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">

Since the alternative is quirks mode, and that creates many inconsistances with other browsers, standards mode is highly desirable.

So, yes that is a good method to centre things.

align:center;

That, on the other hand, is nonsense. There is no align property in CSS.


I have found the problem why this style and many other styles was not working for for ie8 (only for this browser). The problem is that I wrote

<html>

<head>
<title>About us</title>
<link href="css/about.css"  rel="stylesheet" type="text/css" />
</head>

<body>
.......

Now I have changed it to:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>About us</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/about.css"  rel="stylesheet" type="text/css" />
</head>

<body>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜