关于火狐下的兼容问题

本文最后更新于:2023年3月30日 下午

今天说到一个兼容问题到现在没搞明白,就是火狐下,父级的border:20px solid #ccc;overflow: hidden;会对子级的offsetLeft产生影响?到底为什么呢?不知道啊没想通;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 <!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>
<style>
*{margin: 0;padding: 0;list-style: none}
#fu{ position: relative;width: 300px;height: 200px;margin: 100px auto 0px;background: #f40;}
#zi{ position: absolute;left: 0;top:0; width: 200px;height: 100px;background: pink;left:0px;}
/* .cur{border:20px solid #ccc;overflow: hidden;} */
</style>
<script>
window.onload = function() {
var zi = document.getElementById('zi');
console.log(zi.offsetLeft);
// 现在是-1;如果去掉父级#fu的class=“cur”,则打印出来时0
// border:1px solid #ccc;overflow: hidden;会对定位产生影响?求解答......
}
</script>
</head>
<body>
<div id="fu" class="cur">
<div id="zi"></div>
</div>
</body>
</html>

关于火狐下的兼容问题
https://seven3.site/js/关于火狐下的兼容问题/
作者
Seven3s
发布于
2015年1月22日
许可协议