不用js也能实现几个未知高度的容器对齐

本文介绍了一种利用CSS实现多个未知高度容器自适应布局的方法,该方法无需使用JavaScript,在Firefox和Internet Explorer等浏览器中均有效。
css 代码
 
  1. /* easy clearing */  
  2. div#content:after {   /*  overflow:hidden    must be in   div#content  */  
  3.     content: '[DO NOT LEAVE IT IS NOT REAL]';   
  4.     displayblock;  
  5.     height: 0;   
  6.     clearboth;   
  7.     visibilityhidden;  
  8. }  
  9. div#content { displayinline-block; }  
  10. /*\*/  
  11. div#content { displayblock; }  
  12. /* end easy clearing */  
  13. /*\*/  
  14. #secondaryNavigation,#primaryContent{   
  15.     padding-bottom32767px !important;  
  16.     margin-bottom: -32767px !important; }  
  17. @media all and (min-width0px) {  
  18. #secondaryNavigation,#primaryContent {   
  19.     padding-bottom: 0 !important;   
  20.     margin-bottom: 0!important;   
  21. }  
  22. #secondaryNavigation:before,#primaryContent:before{  
  23.     content: '[DO NOT LEAVE IT IS NOTREAL]';   
  24.     displayblock;  
  25.     background: inherit;   
  26.     padding-top32767px!important;  
  27.     margin-bottom: -32767px !important;  
  28.     height: 0;   
  29. }  
  30. }  
content作为外层容器,secondaryNavigation,primarynavgation作为内部容器;

注意:几个容器必须是并行的,并且必须在外层容器上设置 overflow:hidden属性,几个选择器上伪类的定义不可少。
虽然看上去有些杂乱,但如果不用js也能实现几个未知容器高度的自适应 也未尝不是件巧妙的事,更重要的是在ff、ie下均有效,而且屡试不爽。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值