定位也是Css中一个非常强大的属性。定位主要是用来移动盒子,将其移动到我们想要的位置。
定位分为两部分
1、边偏移 left | right |top |bottom:偏移大小;(边偏移一般制定上就不指定下,指定左就不指定右)
2、定位模式 position :static| relative |absolute | fixed
(1)position :static默认值,使用static时 边偏移不起效果。常用于取消定位。
(2)position :relative 相对定位,相对于其原文档流的位置进行定位 可以通过边偏移移动位置,但是原来位置继续占有 每次移动以自己的左上角为基点进行移动
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> /* */ .son1 { width: 100px; height: 100px; background-color: red; } .son2 { width: 100px; height: 100px; background-color: pink; position: relative; left: 90px; top: 50px; } .son3 { width: 100px; height: 100px; background-color: red; } </style> </head> <body> <div class="fa"> <div class="son1"> </div> <div class="son2"> </div> <div class="son3"> </div> </div> </body> </html>