CSS网页布局

来源:互联网 发布:cf 显示网络异常Tp 编辑:程序博客网 时间:2024/05/16 14:28

网页布局有各种各样的方式,这里简单说几种典型常用的布局。

  • 单列布局
    单列布局的话,一般为一个header 一个Main 和一个footer组成。通常用作网站的主页。
    代码实现:
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>一列布局</title><style type="text/css">body{ margin:0; padding:0; font-size:30px}div{ text-align:center; font-weight:bold}.main,.footer{ width:960px; }.head{ width:100%; height:100px; background:#ccc}.main{ height:600px; background:#FCC; margin:0 auto;}.footer{ height:50px; background:#9CF; margin:0 auto;}</style></head><body><div class="head">head</div><div class="main">main</div><div class="footer">footer</div></body></html>

其中margin 0 auto 实现了 Main 和 foote居中显示的作用。

  • 两列布局
    两列布局格局与单列的差别在于,在Main中 包含了 Left 和Right 两个部分 。 实现代码如下:
<!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><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>二列布局</title><style type="text/css">body{ margin:0; padding:0; font-size:30px; font-weight:bold}div{ text-align:center; line-height:50px}.main{ width:960px; height:600px; margin:0 auto}.left{ width:300px; height:600px; background:#ccc; float:left;}/*左浮动样式*/.right{ width:660px; height:600px; background:#FCC; float:right;}/*右浮动样式*/</style></head><body><div class="main">    <div class="left">left</div>    <div class="right">right</div></div></body></html>

用float 实现左右浮动 实现二列布局

  • 三列布局
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>三列布局</title><style type="text/css">body{ margin:0; padding:0; font-size:30px; font-weight:bold}div{ line-height:50px}.left{ width:200px; height:600px; background:#ccc; position:absolute; left:0; top:0}.main{ height:600px; margin:0 310px 0 210px; background:#9CF}.right{ height:600px; width:300px; right:0;top:0; position:absolute; background:#FCC;}</style></head><body>    <div class="left">left</div>    <div class="main">设计首页的第一步是设计版面布局。就象传统的报刊杂志编辑一样,我们将网页看作一张报纸,一本杂志来进行排版布局。 虽然动态网页技术的发展使得我们开始趋向于学习场景编剧,但是固定的网页版面设计基础依然是必须学习和掌握的。它们的基本原理是共通的,你可以领会要点,举一反三。</div>    <div class="right">right</div></body></html>

首先让left 和right 设置绝对位置 position, 之后再确定Main的大小

0 0
原创粉丝点击