fengchuanyu 1 mēnesi atpakaļ
vecāks
revīzija
cc98fba1db
2 mainītis faili ar 106 papildinājumiem un 0 dzēšanām
  1. 62 0
      2_CSS/25_定位2.html
  2. 44 0
      2_CSS/练习9_元素居中.html

+ 62 - 0
2_CSS/25_定位2.html

@@ -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>

+ 44 - 0
2_CSS/练习9_元素居中.html

@@ -0,0 +1,44 @@
+<!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: 400px;
+            border:3px dashed red;
+            position: relative;
+        }
+        /* 父元素 子元素 大小都确定的情况下 */
+        .box2{
+            width: 200px;
+            height: 200px;
+            background-color: blue;
+            position: relative;
+            top:100px;
+            left: 100px;
+        }
+        /* 父元素未知大小 子元素大小已知 */
+        .box3{
+            width: 200px;
+            height: 200px;
+            background-color: green;
+            position: absolute;
+            top:50%;
+            left: 50%;
+            margin-top: -100px;
+            margin-left: -100px;
+        }
+    </style>
+</head>
+<body>
+    <div class="box1">
+        <div class="box2"></div>
+    </div>
+    <div class="box1">
+        <div class="box3"></div>
+    </div>
+</body>
+</html>