左侧容器高度随着右侧容器的高度改变而改变

<!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>MJBlog(mj.588cy.com)</title> 
    <style type="text/css"> 
    * {margin:0;padding:0;font-size:12px;list-style:none;border:0;} 
    body{font-family: Arial, Helvetica, sans-serif; background-color:#edf0eb;} 
    a{ text-decoration:none;} 
    a:hover{ text-decoration:underline;} 
    .clear{ display:block; height:0px; line-height:0px; font-size:0px; clear:both;} 
    .box{ width:960px; margin:20px auto; height:auto; background-color:#FFFFFF; position:relative;} 
    .left{ width:160px; height:100%; background-color:#fafafa; position:absolute; top:0px; left:0px;} 
    .left_wu{ width:160px; height:100%; background-color:#fafafa; float:left;} 
    .left h1,.left_wu h1{ width:160px; height:30px; background-color:#67a727; text-align:center; line-height:30px; color:#FFFFFF; font-size:14px; margin-top:30px;} 
    .nav{ width:160px; height:auto; margin:12px 0px;} 
    .nav a{ width:160px; height:30px; line-height:30px; text-align:center; display:block; color:#588c0e;} 
    .nav a:hover{ background-color:#ebebeb;} 
    .nav .a_dq{ color:#333333; background-color:#ebebeb; font-weight:bold;} 
     
    .right{ width:800px; height:auto; float:right;} 
    .right h1{ width:800px; height:500px; text-align:center; line-height:100px; font-size:14px; font-weight:100;} 
    </style> 
    </head> 
     
    <body> 
    <div class="box"> 
    <div class="right"> 
    <h1>这个是有使用position绝对定位属性,所以左边的导航栏高度会随着父容器高度而变化</h1> 
    </div> 
     
    <div class="clear"></div> 
    <div class="left"> 
    <h1>个人资料</h1> 
    <div class="nav"> 
    <a href="#" class="a_dq">基本信息</a> 
    <a href="#">修改头像</a> 
    <a href="#">帐号绑定</a> 
    <a href="#">个性签名</a> 
    </div> 
    </div> 
    </div> 
     
    <div class="box"> 
    <div class="left_wu"> 
    <h1>个人资料</h1> 
    <div class="nav"> 
    <a href="#" class="a_dq">基本信息</a> 
    <a href="#">修改头像</a> 
    <a href="#">帐号绑定</a> 
    <a href="#">个性签名</a> 
    </div> 
    </div> 
    <div class="right"> 
    <h1>这个是没有使用position绝对定位属性,所以左边的导航栏高度没有随着父容器高度而变化,视觉效果就会差点</h1> 
    </div> 
     
    <div class="clear"></div> 
    </div> 
    </body> 
    </html> 

本方法主要的精髓在于父容器设置position:relative 左侧子容器设置absolute height:100%,这样就可以在父容器高度自适应的同时,左侧容器的高度也能随之改变,适用于左侧导航,右侧为内容区 的情况。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值