123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <!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 {
- position: absolute;
- left: 0;
- top:0;
- background-color: red;
- z-index: 1; /* 设置层级 数字越大越在上面 */
- }
- .div2 {
- position: absolute;
- right: 100px;
- top: 0;
- background-color: blue;
- z-index: 2; /* 设置层级 数字越大越在上面 */
- }
- /* 分组选择器 用","间隔*/
- .div1,.div2 {
- width: 200px;
- height: 200px;
- /* float: left; */
- opacity: 0.5;
- }
- </style>
- </head>
- <body>
- <!-- 文档流 -->
- <!-- absolute fixed 元素脱离了文档流 他们旁边的元素会忽略特们 他们之前所占用的空间会被释放掉-->
- <!-- relative 不会脱离文档流 -->
- <div class="box">
- <div class="div1"></div>
- <div class="div2"></div>
- <span>hello world</span>
- </div>
- </body>
- </html>
|