精彩专题推荐:建站之入门课 建站之必修课 建站之关键课 网站价值所在 流量提高专题 css+div 标准 个人网站打造全过程
  • 让你的网站产生收益赚钱,有博客和网站的绝对不能错过
  • 将指定的流量带到你的网站,为你站增加有效的访客,为你提升业绩
  • 用CSS建设网站的实例

    来源:网络翻译 时间:08-01-09 点击: 点击这里收藏本文

    第二步:创建html模板及文件目录等 1.创建html模板。代码如下:

    <!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>
    <!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,网站结构如下:

    DIV CSS网页布局实例:十步学会用CSS建站

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

    <div id="page-container">
    Hello world.
    </div>
    <div id="page-container">
    Hello world.
    </div>

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

    #page-container {
    width: 760px;
    background: red;
    }
    #page-container {
    width: 760px;
    background: red;
    }

     

     

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

    DIV CSS网页布局实例:十步学会用CSS建站

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

    #page-container {
    width: 760px;
    margin: auto;
    background: red;
    }
    #page-container {
    width: 760px;
    margin: auto;
    background: red;
    }

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

    html, body {
    margin: 0;
    padding: 0;
    }
    html, body {
    margin: 0;
    padding: 0;
    }

    9 7 3 1 2 3 4 5 6 7 8 9 10 4 8 :

    用户评论

    广而告之