1、首先新建一个html文件,命名为test.html。
2、在test.html文件内,使用div标签一个模块,在div内,再使用div标签创建两个内部模块,下面将让两个内部div并排显示。
3、在test.html文件内,分别给每一个div设置class属性,分别为wdiv,fldiv,frdiv。
4、在css标签内,设置class为wdiv的div样式,定义其宽度为500px,高度为400px,背景颜色为灰色。
5、在css标签内,再分别设置class为fldiv和frdiv的样式,定义它们的宽度为240px,高度为350px,同时,使用float属性分别设置一个div浮动向左,另一个浮动向右,从而实现并排显示。
6、最后在浏览器打开test.html文件,查看实现的效果,就完成了。
可以教你一个不算最好,但是最简单的办法,首先你既然已经确认了布局,但是不知道怎么用css写出来,那么你可以想想一下这就是一些框,小框只能放进大框里面。那么整个布局最外面的是一个无颜色的大框<div style="width: 200pxheight: 300px">.....</div>而在这个大框里面又有6个100x100的小框<div style="width: 100pxheight: 100px">.....</div>以此类推,先做好外层的大框,然后在里面放进小框,你只要计算好每个框的大小就能够很轻松的弄出你想要的布局。至于中间的间距我想应该很轻松吧。用的是div的话display一般是用不到的,div用到display一般是用来隐藏或者显示。而position对与你当前的布局也用不到,那是用来定位用的,可以理解为让div脱离其他布局的影响独立出来,所以可能会盖住你原来的布局。float是用在同一层级的排版,比如最外面大框框住的六个小框属于同一层级,但是不同框里面的div是不属于同一层级的,只有同一div里面的同层级div才会在float的影响下对齐排列。所以其实你按照我上面说的计算好宽高的话,float也是可以用不到的。clear也是可以不用。相信你多写一些css以后会理解这些东西的用法的。<div style="width: 200pxheight: 300px">
<div style="width: 98pxheight: 98pxmargin-bottom: 2pxmargin-right: 2pxbackground:red"></div>
<div style="width: 98pxheight: 98pxmargin-bottom: 2pxmargin-right: 2px">
<div style="width: 48pxheight: 48pxmargin-right: 1pxmargin-bottom: 1pxbackground:yellow"></div>
<div style="width: 48pxheight: 48pxmargin-right: 1pxmargin-bottom: 1pxbackground:yellow"></div>
<div style="width: 48pxheight: 48pxmargin-right: 1pxmargin-bottom: 1pxbackground:yellow"></div>
<div style="width: 48pxheight: 48pxmargin-right: 1pxmargin-bottom: 1px background:yellow"></div>
</div>
<div style="width: 98pxheight: 98pxmargin-bottom: 2pxmargin-right: 2pxbackground:orange"></div>
<div style="width: 98pxheight: 98pxmargin-bottom: 2pxmargin-right: 2pxbackground:green"></div>
<div style="width: 98pxheight: 98pxmargin-bottom: 2pxmargin-right: 2px">
....
</div>
<div style="width: 98pxheight: 98pxmargin-bottom: 2pxmargin-right: 2px">
....
</div>
</div>
1. 你实际上只设了小方块的边:#big .small 表示在id为big的元素内部class为small的元素,就是代码中的小方块而已。 如果你要给大小方块同时加边框,要用 #big, .small{border:1px solid #0000FF}2. 利用margin: auto只能使元素水平居中而已, 用css垂直居中元素有些复杂,而且不同浏览器有不同表现,具体解决方法请参照http://www.blueidea.com/tech/web/2006/3231.asp