|
@@ -0,0 +1,66 @@
|
|
|
|
+<!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: 5px solid black;
|
|
|
|
+ position: relative; /* 设置为相对定位 */
|
|
|
|
+ }
|
|
|
|
+ .div1{
|
|
|
|
+ width: 100px;
|
|
|
|
+ height: 100px;
|
|
|
|
+ background-color: red;
|
|
|
|
+ /* margin-top: -20px; 向上移动20px 负数向相反方向移动*/
|
|
|
|
+ /* 相对定位 相对于原来的位置 */
|
|
|
|
+ /*position: relative; 设置为相对定位 */
|
|
|
|
+ /* top: 300px;
|
|
|
|
+ left:300px; */
|
|
|
|
+
|
|
|
|
+ /* 相对于最近的已定位祖先元素 */
|
|
|
|
+ /* absolute 定位 需要满足两个条件 */
|
|
|
|
+ /* 第一个必须是他的祖先元素 */
|
|
|
|
+ /* 第二个必须使用定位 */
|
|
|
|
+ position: absolute; /* 设置为绝对定位 */
|
|
|
|
+ right: 20px;
|
|
|
|
+ bottom: 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ .div2{
|
|
|
|
+ width: 100px;
|
|
|
|
+ height: 100px;
|
|
|
|
+ background-color: blue;
|
|
|
|
+ /* 相对于浏览器窗口 */
|
|
|
|
+ position: fixed; /* 设置为固定定位 */
|
|
|
|
+ right: 50px;
|
|
|
|
+ bottom: 50px;
|
|
|
|
+ }
|
|
|
|
+ </style>
|
|
|
|
+</head>
|
|
|
|
+<body>
|
|
|
|
+ <div class="box">
|
|
|
|
+ <div class="div1"></div>
|
|
|
|
+ </div>
|
|
|
|
+ <div class="box">
|
|
|
|
+ <div class="div1"></div>
|
|
|
|
+ </div>
|
|
|
|
+ <div class="box">
|
|
|
|
+ <div class="div1"></div>
|
|
|
|
+ </div>
|
|
|
|
+ <div class="box">
|
|
|
|
+ <div class="div1"></div>
|
|
|
|
+ </div>
|
|
|
|
+ <div class="box">
|
|
|
|
+ <div class="div1"></div>
|
|
|
|
+ </div>
|
|
|
|
+ <div class="box">
|
|
|
|
+ <div class="div1"></div>
|
|
|
|
+ </div>
|
|
|
|
+
|
|
|
|
+ <div class="div2"></div>
|
|
|
|
+</body>
|
|
|
|
+</html>
|