<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
*{
margin: 0;
padding: 0;
}
.box-one{
position: relative;
width: 300px;
height: 300px;
margin-left: 100px;
background-color: deeppink;
}
.box-two{
width: 200px;
height: 200px;
margin-left: 50px;
background-color: yellowgreen;
}
.box-three{
position: absolute;
left: 100px;
width: 100px;
height: 100px;
background-color: deepskyblue;
}
.box-four{
position: absolute;
width: 300px;
height: 300px;
background-color: red;
}
.box-four .box-five{
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
margin: auto;
width: 50px;
height: 50px;
background-color: chartreuse;
}
</style>
</head>
<body>
<div class="box-one">
<div class="box-two">
<div class="box-three"></div>
</div>
</div>
<div class="box-four">
<div class="box-five"></div>
</div>
<!--
position: relative;相对定位
left: 100px;
相对定位的参考物是自身原来的位置
相对定位的元素还在文档流中占据原来的位置 但是可以在新的地方出现不占据位置
position: absolute;绝对定位
绝对定位的参考物默认是浏览器窗口
也可以指定任意一个最近的position:relative/absolute/fixed的祖先元素作为参考物
绝对定位的元素不在文档流占据原来的位置
position:fixed 固定定位
固定定位的参考物是浏览器窗口
z-index 设置绝对/固定/相对定位元素的层级 定位都是会飘的 可以飘上飘下
auto(默认) 所有在普通文档流的元素
数值 举个例子 z-index:20
.box-four .box-five{
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
margin: auto;
width: 50px;
height: 50px;
background-color: chartreuse;
}
既有浮动又有定位的情况
定位比浮动飘的高
-->
</body>
</html>
Python3Turtle