webveuje/teaching/lhj/kejian/position.html
2021-04-29 17:16:40 +08:00

53 lines
1.5 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=], initial-scale=1.0">
<title>Document</title>
<style>
/*
position
绝对定位 他的参照物不是他自己 如果父盒子不被relative修饰他的参照物就是最外层盒子body 如果父盒子被relative修饰 他的参照物就是父盒子
相对定位 以他自己为参照物
子绝父相
固定定位 fixed
粘性 sticky 滚动条不动的时候 他相当于相对定位 滚动条滚动的时候 他相当于fixed 固定定位
*/
*{
margin: 0;
padding: 0;
}
.box{
width:400px;
height: 400px;
background: green;
margin: auto;
margin-top: 50px;
position: relative;
}
.item{
width: 200px;
height: 200px;
background: blue;
position: absolute;
top: 0;
left:0
}
.shu{
width: 10px;
height: 500px;
background-color: aliceblue;
}
</style>
</head>
<body>
<div style="position: sticky; top: 0; ">aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</div>
<div class="box">
<div class="item"></div>
</div>
<div class="shu"></div>
</body>
</html>