您现在的位置: PQ秀秀网 >> 网页设计 >> HTML-XHTML-CSS >> 正文 用户登录 新用户注册
用css网站布局之十步实录!(二)
作者:佚名    教程来源:不详    点击数:加载中...    更新时间:2008-4-26 字体:[ ]
添加到收藏: 添加到百度收藏  收藏到QQ书签  添加到雅虎收藏  添加到新浪ViVi  添加到天极网摘  添加到和讯网摘

第二步:创建html模板及文件目录等

1.创建html模板。
  代码如下:
Example Source Code [

<!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>


  将其保存为index.html,并创建文件夹css,images,网站结构如下:



2.创建网站的大框:
  建立一个宽760px的盒子,它将包含网站的所有元素。
  在html文件的<body>和</body>之间写入

div css xhtml xml Example Source Code Example Source Code [ <div id="page-container">
Hello world.
</div>


  创建css文件,命名为master.css,保存在/css/文件夹下。写入:

div css xhtml xml Example Source Code Example Source Code [ #page-container {
width: 760px;
background: red;
}


  控制html的id为page-container的盒子的宽为760px,背景为红色。

  现在为了让盒子居中,写入margin: auto;,使css文件为:

div css xhtml xml Example Source Code Example Source Code #page-container {
width: 760px;
margin: auto;
background: red;
}


  现在你可以看到盒子和浏览器的顶端有8px宽的空隙。这是由于浏览器的默认的填充和边界造成的。消除这个空隙,就需要在css文件中写入:

div css xhtml xml Example Source Code Example Source Code [ html, body {
margin: 0;
padding: 0;
}
教程录入:andy    责任编辑:andy 
  网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)