码迷,mamicode.com
首页 > 其他好文 > 详细

相对定位引起的留白处理

时间:2014-08-07 18:42:00      阅读:238      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   使用   os   io   ar   

<!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>
</head>
<style>
* { margin:0; padding:0; }
div { width:100%; margin:0 auto; float:left; clear:both; }
#header { height:300px; background:green; }
#box_wrap { height:auto; }
#box { height:900px; width:400px; background:blue; float:none; position:relative; top:-200px;  }
#footer_wrap { position:relative; height:auto; } /*提供一个定位点,高度为 0 */
#footer { height:300px; background:yellow; position:absolute; top:-200px;  } /* 需使用绝对定位 */
</style>
<body>
<!-- box 使用相对定位,定位到header层之上。会留出一段空白。目标就是消除该段空白! -->
<div id="header"></div>

<div id="box_wrap">    <!-- 用于 box 定位,有了这个,box 用 margin 居中才能生效! -->
    <div id="box"></div>
</div>

<div id="footer_wrap"> <!-- 用于 footer 定位,从而能使 footer 紧接在 box 后面 -->
    <div id="footer"></div>
</div>

</body>
</html>

 

相对定位引起的留白处理,布布扣,bubuko.com

相对定位引起的留白处理

标签:style   blog   http   color   使用   os   io   ar   

原文地址:http://www.cnblogs.com/lxpursue/p/3897730.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!