用css网站布局之十步实录!(二)-CSS布局实例
来源:无忧整理 作者:Jorux
更新时间:2007-01-16
点击:
第二步:创建html模板及文件目录等
1.创建html模板。
代码如下:
Example Source Code [www.mb5u.com]
将其保存为index.html,并创建文件夹css,images,网站结构如下:

2.创建网站的大框:
建立一个宽760px的盒子,它将包含网站的所有元素。
在html文件的<body>和</body>之间写入
Example Source Code [www.mb5u.com]
创建css文件,命名为master.css,保存在/css/文件夹下。写入:
Example Source Code [www.mb5u.com]
控制html的id为page-container的盒子的宽为760px,背景为红色。
现在为了让盒子居中,写入margin: auto;,使css文件为:
Example Source Code [www.mb5u.com]
现在你可以看到盒子和浏览器的顶端有8px宽的空隙。这是由于浏览器的默认的填充和边界造成的。消除这个空隙,就需要在css文件中写入:
Example Source Code [www.mb5u.com]
1.创建html模板。
代码如下:
Example Source Code [www.mb5u.com]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
<title>CompanyName - PageName</title>
<meta http-equiv="Content-Language" content="en-us" />
<meta http-equiv="imagetoolbar" content="no" />
<meta name="MSSmartTagsPreventParsing" content="true" />
<meta name="description" content="Description" />
<meta name="keywords" content="Keywords" />
<meta name="author" content="Enlighten Designs" />
<style type="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>
<meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
<title>CompanyName - PageName</title>
<meta http-equiv="Content-Language" content="en-us" />
<meta http-equiv="imagetoolbar" content="no" />
<meta name="MSSmartTagsPreventParsing" content="true" />
<meta name="description" content="Description" />
<meta name="keywords" content="Keywords" />
<meta name="author" content="Enlighten Designs" />
<style type="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 [www.mb5u.com]<div id="page-container">
Hello world.
</div>
Hello world.
</div>
创建css文件,命名为master.css,保存在/css/文件夹下。写入:
Example Source Code [www.mb5u.com]#page-container {
width: 760px;
background: red;
}
width: 760px;
background: red;
}
控制html的id为page-container的盒子的宽为760px,背景为红色。
现在为了让盒子居中,写入margin: auto;,使css文件为:
Example Source Code [www.mb5u.com]#page-container {
width: 760px;
margin: auto;
background: red;
}
width: 760px;
margin: auto;
background: red;
}
现在你可以看到盒子和浏览器的顶端有8px宽的空隙。这是由于浏览器的默认的填充和边界造成的。消除这个空隙,就需要在css文件中写入:
Example Source Code [www.mb5u.com]html, body {
margin: 0;
padding: 0;
}
margin: 0;
padding: 0;
}
相关CSS布局实例:
最新评论:
评论加载中....
发表评论:不能超过250字节,请自觉遵守互联网相关政策法规.
- 昵称: 验证:







