|
|
@@ -0,0 +1,62 @@
|
|
|
+<!DOCTYPE html>
|
|
|
+<html lang="en">
|
|
|
+<head>
|
|
|
+ <meta charset="UTF-8">
|
|
|
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
+ <title>Document</title>
|
|
|
+ <style>
|
|
|
+ .box1{
|
|
|
+ width: 400px;
|
|
|
+ height: 4000px;
|
|
|
+ border:3px dashed red;
|
|
|
+ position: relative;
|
|
|
+
|
|
|
+ }
|
|
|
+ .box2{
|
|
|
+ width: 200px;
|
|
|
+ height: 200px;
|
|
|
+ background-color: blue;
|
|
|
+ /* absolute 绝对定位 会脱离文档流 会释放掉之前的空间 */
|
|
|
+ position: absolute;
|
|
|
+ top:50px;
|
|
|
+ z-index: 1;
|
|
|
+ }
|
|
|
+ /* 定位元素 默认情况下可以覆盖正常文档流中的元素 */
|
|
|
+ /* 如果两个定位元素重叠 后面的定位元素会覆盖前面的定位元素 */
|
|
|
+ /* 如果想调整两个元素的覆盖层级 可以使用 z-index 属性 数值越大 覆盖层级越高 */
|
|
|
+ .box3{
|
|
|
+ width: 100px;
|
|
|
+ height: 100px;
|
|
|
+ background-color: green;
|
|
|
+ position: absolute;
|
|
|
+ top:30px;
|
|
|
+ z-index: 2;
|
|
|
+ }
|
|
|
+ /* z-index 属性仅能应用于定位元素 */
|
|
|
+ span{
|
|
|
+ background-color: yellow;
|
|
|
+ font-size: 100px;
|
|
|
+ z-index: 3;
|
|
|
+ }
|
|
|
+ .box4{
|
|
|
+ font-size: 50px;
|
|
|
+ /* 固定定位 相较于浏览器 窗口进行定位 */
|
|
|
+ /* 固定定位 会脱离文档流 会释放掉之前的空间 */
|
|
|
+ position: fixed;
|
|
|
+ right: 0;
|
|
|
+ bottom: 0;
|
|
|
+ }
|
|
|
+ </style>
|
|
|
+</head>
|
|
|
+<body>
|
|
|
+ <div class="box1">
|
|
|
+ <div class="box2"></div>
|
|
|
+ <div class="box3"></div>
|
|
|
+ <span>这是一个span标签</span>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div class="box4">
|
|
|
+ 返回顶部
|
|
|
+ </div>
|
|
|
+</body>
|
|
|
+</html>
|