老师,如果div2,只设置固定定位,不设置偏移量,我的login就不见了,他去哪里了呢?
来源:4-2 侧边栏导航跟随案例
慕设计6170877
2020-05-29 17:38:10
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
*{
margin: 0;
padding: 0;
}
html,body{
width: 100%;
height: 100%;
}
.con{
height: 4000px;
width: 100%;
background: url('../img/mooc.png') center top no-repeat;
}
.div1{
height: 100%;
width: 100%;
background: url('../img/opacity.png') no-repeat;
position:fixed;
top: 0;
left:0;
}
.div2{
height: 360px;
width: 360px;
background: url('../img/login.png') no-repeat;
position: fixed;
/* top: 50%;
left: 50%;
margin-top: -180px;
margin-right: -180px; */
/* top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto auto; */
}
</style>
</head>
<body>
<div class="con"></div>
<div class="div1"></div>
<div class="div2"></div>
</body>
</html>
1回答
同学你好,因为固定定位元素是参考窗口进行定位的,不设置偏移量时,默认是挨着页面中上一个元素进行布局的,div1设置固定定位脱离了文档流,所以div2默认会在con元素后面显示,但是由于con设置了固定高度超出窗口高度,导致div2在窗口外显示,所以我们看不到div2.
如果我的回答帮助到了你,欢迎采纳,祝学习愉快~
相似问题