+ -
当前位置:首页 → 问答吧 → 请教关于页面元素层叠排列的问题

请教关于页面元素层叠排列的问题

时间:2011-06-01

来源:互联网

参考的页面地址:http://aiyuchen.tap.cn/
所要用到的工具:firebug、web develope
页面区域:共四处
23.jpg (41.61 KB)
2011-6-1 09:33


打开firebug可以看到这四处是一列并排的DIV
24.jpg (18.22 KB)
2011-6-1 09:33



  • 查看这四处DIV的样式不包含:position、background,却实现了DIV层叠排列
  • 我用web develope 将JS全部禁用,页面正常显示
  • 查看四处DIV的样式,每个DIV都有类似“margin: 0 -662px 0 -614px;”这样的margin属性


我想问下这样的原理怎么实现的,有没有相关的技术文章提供参考。

[ 本帖最后由 feigege 于 2011-6-1 09:38 编辑 ]

作者: feigege   发布时间: 2011-06-01

我懂为什么了,代码如下。只是我不明白,为什么要这么做,而不直接使用position呢?
<!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>CSS 浮动层</title> <style type="text/css"> <!-- #parent { width: 600px; height: 600px; overflow: hidden; background: #ccc; } .ah { width: 100%; background: #666; overflow: hidden; float: left; } #son_1, #son_2, #son_3, #son_4 { width: 60px; height: 60px; margin: 0 -600px; float: left; } #son_1 { margin: 0 -500px 0 -612px; background: #c00; } #son_2 { margin-top: 60px; } #son_3 { margin-top: 60px; } #son_4 { margin-top: 60px; } --> </style> </head> <body> <div id="parent"> <div class="ah">&nbsp;</div> <div id="son_1">son_1</div> <div id="son_2">son_2</div> <div id="son_3">son_3</div> <div id="son_4">son_4</div> </div> </body> </html>
 提示:您可以先修改部分代码再运行

作者: feigege   发布时间: 2011-06-01