1.创建html模板。
代码如下:
Example Source Code
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<metahttp-equiv="Content-type"content="text/html;charset=UTF-8"/>
<title>CompanyName-PageName</title>
<metahttp-equiv="Content-Language"content="en-us"/>
<metahttp-equiv="imagetoolbar"content="no"/>
<metaname="MSSmartTagsPreventParsing"content="true"/>
<metaname="description"content="Description"/>
<metaname="keywords"content="Keywords"/>
<metaname="author"content="EnlightenDesigns"/>
<styletype="text/css"media="all">@import"css/master.css";</style>
</head>
<body>
</body>
</html>
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<metahttp-equiv="Content-type"content="text/html;charset=UTF-8"/>
<title>CompanyName-PageName</title>
<metahttp-equiv="Content-Language"content="en-us"/>
<metahttp-equiv="imagetoolbar"content="no"/>
<metaname="MSSmartTagsPreventParsing"content="true"/>
<metaname="description"content="Description"/>
<metaname="keywords"content="Keywords"/>
<metaname="author"content="EnlightenDesigns"/>
<styletype="text/css"media="all">@import"css/master.css";</style>
</head>
<body>
</body>
</html>
将其保存为index.html,并创建文件夹css,images,网站结构如下:
2.创建网站的大框:
建立一个宽760px的盒子,它将包含网站的所有元素。
在html文件的<body>和</body>之间写入
Example Source Code
<divid="page-container">
Helloworld.
</div>
Helloworld.
</div>
创建css文件,命名为master.css,保存在/css/文件夹下。写入:
Example Source Code
#page-container{
width:760px;
background:red;
}
width:760px;
background:red;
}
控制html的id为page-container的盒子的宽为760px,背景为红色。
现在为了让盒子居中,写入margin:auto;,使css文件为:
Example Source Code]
#page-container{
width:760px;
margin:auto;
background:red;
}
width:760px;
margin:auto;
background:red;
}
现在你可以看到盒子和浏览器的顶端有8px宽的空隙。这是由于浏览器的默认的填充和边界造成的。消除这个空隙,就需要在css文件中写入:
Example Source Code[
html,body{
margin:0;
padding:0;
}
margin:0;
padding:0;
}