<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <style type="text/css"> /* 相对定位特点 1.不会离文档流 占位 所有后面的元素不会往前跑 2.可以设置上下左右四个方位 如果同的设置了top和bottom值只有top起作用 如果同时设置了1et和right值只有1eft起作用 3.参照物:自已本身 4.可以设置zinde属性z-ine越大越在上 z-index必须要和定位元素(绝对,相利,固定)同时使用才起作用 */ .red{ width: 300px; height: 300px; background-color: red } .green{ width: 200px; height: 200px; background-color: green; position: relative; left: 50px; top: 50px; z-index: 10; } .blue{ width: 100px; height: 100px; background-color: blue; position: relative; z-index: 11; } </style> </head> <body> <div class="red"> <div class="green"></div> <div class="blue"></div> </div> </body> </html>
发表评论