博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
IE7下元素的 'padding-top' 遇到 'clear' 特性在某些情况下复制到 'padding-bottom'
阅读量:6934 次
发布时间:2019-06-27

本文共 1531 字,大约阅读时间需要 5 分钟。

项目中使用的是DIV+CSS布局,有一个页面是同事完成的,这几天他请假有事。项目发现一个UI Bug。在IE7下,某一个Div的padding-top会让整个div产生padding-bottom样式。在IE8/9、Firefox、Chrome下都是OK。

 

通过搜索发现是发现问题的答案:

链接地址是:

在项目开发过程中,开发人员为了让div的高度随着内容自动增加,所以经常在div的关闭之前会添加一个类似clearfix的div。这个div的结构如下:

<div class=”clearfix”>&nbsp;</div> 样式是: .clearfix{clear: both;}。通过上面链接的解释是未触发hasLayout 特性。平时对这个特性接触的不多,所以不是很明白。

 

但是之前的项目我们也未采用链接所说的解决方案,但是项目的兼容性是很不错的。后来通过查看之前项目的代码,我们在给最外层的div添加一个高度时,padding-bottom样式不会出现。但是我们此时内容无法自动扩充。

 

所以在需要自动扩展内容的div中嵌入一个<div class=”clearfix”></div>,此时最外层不能添加height,达到内容自动扩充。代码如下:

1: <html xmlns="http://www.w3.org/1999/xhtml">
2: <head>
3: <title>元素"padding-top"会出现"padding-bottom" in IE7中</title>
4: <style type="text/css">
5: body
6: {
7: padding:0;
8: margin:0;
9: }
10: .clearfix
11: {
12: clear:both;
13: height:0;
14: }
15: #container
16: {
17:
18: background:#CCC;
19:
20: border:2px solid black;
21: padding-top:10px;
22:
23: }
24: .leftpanel
25: {
26: float:left; width:50px; height:100px; background:#666;
27: }
28: .rightpanel
29: {
30: float:left; width:500px; background:green;
31: }
32: </style>
33: </head>
34: <body>
35: <div id="container">
36: <div class="leftpanel">Left Panel Content Here!</div>
37:
38: <div class="rightpanel">Right Panel Content Here!Right Panel Content Here!
39: Right Panel Content Here!Right Panel Content Here!
40: Right Panel Content Here!Right Panel Content Here!<div class="clearfix"></div></div>
41: <div style="clear:both;"></div>
42: </div>
43: </body>
44: </html>

 

转载于:https://www.cnblogs.com/liminjun88/archive/2012/03/29/2422901.html

你可能感兴趣的文章
logstash 自动重新加载配置
查看>>
装系统w7、ubuntu、centos等系统(一)
查看>>
spring-boot-mybatis
查看>>
【问题解决】连接mysql 8错误:authentication plugin 'caching_sha2_password
查看>>
Jenkins使用遇到的问题总结
查看>>
Python从菜鸟到高手(2):清空Python控制台
查看>>
几道有意思的逻辑分析题
查看>>
Cracking the coding interview--Q1.2
查看>>
Permission denied: user=root, access=WRITE, inode="/":hadoopuser:supergroup:drwxr-xr-x
查看>>
p-unit - 单元级别开源性能测试框架
查看>>
WinForm 实现两个容器之间控件的拖动及排列(图文)
查看>>
C/C++版数据结构之链表<三>
查看>>
CentOS下实现postgresql开机自启动
查看>>
libxml解析的attributes参数理解
查看>>
VK Cup 2012 Qualification Round 1 E. Phone Talks
查看>>
volcanol_Linux_问题汇总系列_1_系统引导过程中到check filesystem时就无法继续引导问题解决方法。...
查看>>
XP局域网访问无权限、不能互相访问问题的完整解决方案
查看>>
使用xml布局菜单
查看>>
我的大学四年
查看>>
编译可在Android上运行的qemu user mode
查看>>