DIV+CSS难点之经验总结
1、网页居中显示:
需要设置两个地方,一个是body,一个是外边框div。
CSS:
body{
margin:0;
padding:0;
text-align:center;
}
#main{ /*最外层DIV*/
width:760px;
margin:0 auto;
padding:0
}
2、文字垂直居中显示:
在DIV中定义一个行高与其高度相同即可。
CSS:
.title{
height:25px;
line-height:25px;
vertical-align:middle;
}
3、图片垂直居中显示:
在<img>标签中加入align="absmiddle"
即可。
4、清除浮动:
如果在同一行上有几个DIV并列显示,那么必须在其中加入清除浮动代码,如果在一行上只是一个DIV,好象不必清除浮动。
CSS:
.clear{clear: both;}
HTML示例:
<div id="main">
<div
class="left"></div>
<div
class="center"></div>
<div
class="right"></div>
<div
class="clear"></div>
</div>
<!--清除浮动后,后面的
代码排列就不会有任何变形了,不管是在IE还是FF中,都很正确-->
<div ……
5、三列结构中的的DIV写法:
适用于左右栏是窄幅,中栏为主要内容显示,让其宽度自适应。
CSS:
#main{
width:760px;
margin:0 auto;
}
.left{
width:100px;
float:left;
}
.right{
width:120px;
float:right;
}
.center{
margin:0
120px 0 100px;/*页面
相关文档:
原文网址:http://www.complexspiral.com/publications
Containing Floats
As powerful and useful as they are, floats can make for tricky layout tools. Chances are that you may have seen something like the situation shown in Figure 1, which is accomplished with just two div elements, each with a floate ......
网页设计DIV+CSS元素解析,<head>部分前:
(一) DOCTYPE 和DTD
用DW新建网页时,总会生成一句
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
这句是DOCTYPE声明,DOCTY ......
前言:CSS布局与传统表格(table)布局最大的区别在于:原来的定位都是采用表格,通过表格的间距或者用无色透明的GIF图片来控制文布局版块的间距;而现在则采用层(div)来定位,通过层的margin,padding,border等属性来控制版块的间距。
(一) CSS2盒模型
盒模型主要定义四个区域:内容(content)、边框距(paddin ......
1 导入外部js文件:
1.<script type="text/javascript" src="myjs/xx.js"></script>
2.<script language="javascript" src="myjs/xx.js"></script>
2 导入外部css文件:
<link rel="stylesheet" ty ......