fengchuanyu 2 тижнів тому
батько
коміт
4152dabeda
2 змінених файлів з 120 додано та 0 видалено
  1. 58 0
      2-CSS/18_定位.html
  2. 62 0
      2-CSS/练习11_两列布局.html

+ 58 - 0
2-CSS/18_定位.html

@@ -0,0 +1,58 @@
+<!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>
+        .box{
+            width: 400px;
+            height: 400px;
+            border: 3px solid black;
+            /* 设置为相对定位  相对于自己的位置*/
+            position: relative; 
+            top:100px;
+            left:200px;
+        }
+        .div1{
+            width: 100px;
+            height: 100px;
+            background-color: red; 
+            /* 绝对定位的元素的位置相对于最近的已定位祖先元素 如果元素没有已定位的父元素,那么它的位置相对于<html>*/
+            position: absolute; /* 设置为绝对定位 */
+            /* right: 0;
+            bottom: 0; */
+            /* top: 100px;
+            left: 50px; */
+            top:50%;
+            left:50%;
+            margin-top:-50px;
+            margin-left: -50px;
+            z-index: 1; /* 设置层级  数字越大越在上面 */
+        }
+        /* 固定定位的元素的位置相对于浏览器窗口 */
+        .div2{
+
+            position: fixed;
+            right: 50px;
+            bottom: 50px;
+        }
+        .div3{
+            width: 100px;
+            height: 100px;
+            background-color: blue;
+            position: absolute;
+            top: 200px;
+            left: 200px;
+            z-index: 2; /* 设置层级  数字越大越在上面 */
+        }
+    </style>
+</head>
+<body>
+    <div class="box">
+        <div class="div1"></div>
+        <div class="div3"></div>
+    </div>
+    <div class="div2">返回顶部</div>
+</body>
+</html>

+ 62 - 0
2-CSS/练习11_两列布局.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>
+        /* css reset */
+        body{
+            margin: 0;
+        }
+        /* 工具类 */
+        .clearfix::after{
+            content: "";
+            display: block;
+            clear: both; /* 清除浮动 */
+        }
+
+        .header{
+            height: 100px;
+            background-color: #4CAF50;
+            overflow: hidden;
+        }
+        .content .left{
+            width: 300px;
+            height: 200px;
+            background-color: blue;
+            float: left; /* 左侧浮动 */
+        }
+        .content .right{
+            height: 200px;
+            width: calc(100% - 300px); /* calc 计算符号左右两边必须要有空格 */
+            background-color: red;
+            float: left;
+        }
+        .footer{
+            height: 100px;
+            background-color:aqua ;
+            overflow: hidden;
+        }
+    </style>
+</head>
+<body>
+    <div class="container">
+        <div class="header">
+            <h1>我的网页</h1>
+        </div>
+        <div class="content clearfix">
+            <div class="left">
+                <h2>左侧内容</h2>
+            </div>
+            <div class="right">
+                <h2>右侧内容</h2>
+            </div>
+        </div>
+        <div class="footer">
+            <p>版权所有 &copy; 2024</p>
+        </div>
+    </div>
+    
+</body>
+</html>