动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
   网页设计 → 阅读文章

 CSS布局自适应高度解决方法

作者:设计中国 来源:设计中国 
阅读 2456 人次 , 2006-2-16 14:54:00 

这是一个比较典型的三行二列布局,每列高度(事先并不能确定哪列的高度)的相同,是每个设计师追求的目标,按一般的做法,大多采用背景图填充、加JS脚本的方法使列的高度相同,本文要介绍的是采用容器溢出部分隐藏和列的负底边界和正的内补丁相结合的方法来解决列高度相同的问题。

先看代码:

#wrap{

overflow: hidden;

}

#sideleft, #sideright{

padding-bottom: 32767px;

margin-bottom: -32767px;

}

实现原理:

块元素必须包含在一个容器里。

应用overflow: hidden 到容器里的元素。

应用 padding-bottom(足够大的值)到列的块元素 。

应用margin-bottom(足够大的值)到列的块元素。

padding-bottom将列拉长变的一样高,而负的margin-bottom又使其回到底部开始的位置,同时,溢出部分隐藏掉了。

兼容各浏览器

IE Mac 5

得到高度正确,所以要过滤掉上面的代码。

/*\*/

#sideleft, #sideright{

padding-bottom: 32767px;

margin-bottom: -32767px;

}

/**/

Opera

1. Opera7.0-7.2不能正确清除溢出部分,所以要加:

/* easy clearing */

#wrap:after

{

content: '[DO NOT LEAVE IT IS NOT REAL]';

display: block;

height: 0;

clear: both;

visibility: hidden;

}

#wrap

{

display: inline-block;

}

/*\*/

#wrap

{

display: block;

}

/* end easy clearing */

/*\*/



2. Opera8处理overflow: hidden有个BUG,还得加上以下代码:

/*\*/

#sideleft, #sideright

{

padding-bottom: 32767px !important;

margin-bottom: -32767px !important;

}

@media all and (min-width: 0px) {

#sideleft, #sideright

{

padding-bottom: 0 !important;

margin-bottom: 0 !important;

}

#sideleft:before, #sideright:before

{

content: '[DO NOT LEAVE IT IS NOT REAL]';

display: block;

background: inherit;

padding-top: 32767px !important;

margin-bottom: -32767px !important;

height: 0;

}

}

/**/

3.Opera9的B2在修正8的bug.

测试环境:IE5.01、IE5.5、IE6.0、Firefox1.5、Opera8.5、Netscape 7.2通过。



  
 本文Tagshtml/css  
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:CSS 的十八般技巧
· 下一篇:!important和(空格)/**/:的组合技巧及其他 选项
· 无刷新变换BANNER特效代码
· 什么是web标准?
· 驳“AJAX 的七宗罪”
· FrontPage XP直通车第4站——样式表的应用
· DW MX 设计留言本实战(4)


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077