在应用了属性transform的父元素上,若其拥有fixed属性的子元素,则该子元素的fixed属性讲失效,并将以其父元素为定位基准

详情请看例子:

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
27
28
29
30
31
32
33
34
35
36
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<style>
.outer {
overflow: hidden;
width: 300px;
height: 300px;
background: yellow;
}
.mid {
margin: 20px;
width: 200px;
height: 200px;
transform: translate(0, 0);
background: greenyellow;
}
.inner {
position: fixed;
top: 0;
left: 0;
width: 100px;
height: 100px;
background: pink;
}
</style>
<body>
<div class="outer">
<div class="mid">
<div class="inner"></div>
</div>
</div>
</body>
</html>

以上代码所呈现的布局样式:

transform

若我们删除去父元素的transform属性:

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
27
28
29
30
31
32
33
34
35
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<style>
.outer {
overflow: hidden;
width: 300px;
height: 300px;
background: yellow;
}
.mid {
margin: 20px;
width: 200px;
height: 200px;
background: greenyellow;
}
.inner {
position: fixed;
top: 0;
left: 0;
width: 100px;
height: 100px;
background: pink;
}
</style>
<body>
<div class="outer">
<div class="mid">
<div class="inner"></div>
</div>
</div>
</body>
</html>

transform2

由此可见,其父元素的transform对fixed子元素的影响;

注,此实例在chorme以及firefox下有效,IE环境等不受影响