首页 > 代码库 > CSS的定位

CSS的定位

CSS position 属性

position的属性值有4个,分别是:

1.static(静态定位)

2.relative(相对定位)

3.absolute(绝对定位)

4.fixed(固定定位)

最常见的就是relative和absolute结合起来一起用,将所在的父级设置为relative,子级设置为absolute,将所在的父级当做坐标的0,0点;如:

<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
.box{
width: 400px;
height: 400px;
background-color: darkgoldenrod;
position: relative;
}
.box1{
width: 100px;
height: 100px;
background-color: darkblue;
position: absolute;
left: 100px;
top: 100px;
}
</style>
</head>
<body>
<div class="box">
<div class="box1"></div>
</div>
</body>
</html>

 

CSS的定位