日期:2014-05-17 浏览次数:20679 次
DIV和CSS能写出千变万化的网页样式。很久很久以前就学过了,但感觉还是有必要小记一下!
先来个基本框架
<!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=gb2312" /> <title>我的网页</title> </head> <body> </body> </html>
在head中加入
<link rel="stylesheet" type="text/css" href="css/style.css" />
一般网站会分为4部分:header,sidebar,content,footer
于是写上4个div标签
<div id="header"> </div> <div id="sidebar"> <h1></h1> <div> </div> </div> <div id="content"> <h1></h1> <div> </div> </div> <div id="footer"> </div>
<div id="header"> <ul> <li><a href="index.asp">首页</a></li> <li><a href="reg.asp">注册</a></li> <li><a href="blog.asp">博友</a></li> <li><a href="photo.asp">相册</a></li> <li><a href="photo.asp">风格</a></li> </ul> </div>
<div id="footer"> <p>友情链接 | 关于我们 | 版权声明 | 广告赞助 | 招贤纳士</p> <p>CopyRight (C) 2012 blog.csdn.net/xn4545945 All Right Reseved.</p> </div>
接下来就是用CSS来设置4个div的排列方式了。
先设置一下全局的样式:
* {
margin:0;
padding:0;
}
body {
font-size:14px;
color:#333;
width:900px;
margin:10px auto;
position:relative;
background:#fff;
}
ul {
list-style-type:none;
}#header {
width:900px;
height:200px;
background:url(../images/logo.jpg) no-repeat 30px 30px;
border:1px solid #ccc;
margin-bottom:10px;
}
#header ul {
margin-top:160px;
margin-left:auto;
width:430px;
}
#header ul li {
float:left;
width:70px;
height:30px;
}
#header ul li a {
color:#333;
text-decoration:none;
}#sidebar {
width:300px;
height:600px;
float:left;
margin-bottom:10px;
}
#sidebar h1 {
background:#ccc;
height:25px;
line-height:25px;
font-size:14px;
text-indent:10px;
}
#sidebar div {
border-left:1px solid #ccc;
border-right:1px solid #ccc;
border-bottom:1px solid #ccc;
height:250px;
}#content {
width:580px;
height:600px;
float:right;
margin-bottom:10px;
}
#content h1 {
background:#ccc;
height:25px;
line-height:25px;
font-size:14px;
text-indent:10px;
}
#content div {
border-left:1px solid #ccc;
border-right:1px solid #ccc;
border-bottom:1px solid #ccc;
height:550px;
}#footer {
width:900px;
height:60px;
clear:both;
border-top:1px solid #999;
}
#footer p {
text-align:center;
padding-top:10px;
}看看写完的效果吧!(图片是后来加上的)

还有一个问题就是可以抽取公共部分!
一般在ASP中可以讲header与footer公共部分抽取出来,只需要把footer的div部分剪切出来,保存成htm文件,然后用