position:fixed失效情况

<!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>
body{height:2000px;transform:translate(0);}
.fixed{position:fixed;100px;height:100px;background:red;top:300px;}
</style>
</head>

<body>
<div class="fixed">固定定位元素</div>
</body>
</html>

fixed定位的元素,如果父级有transform样式,值不为none,那么fixed定位就会失效。

解决方法:使用transform样式的元素,不要包含fixed定位的子元素。

原文地址:https://www.cnblogs.com/liaohongwei/p/10649685.html