position属性值:
static,absolute,relative,fixed,sticky
{
/* 全局值 */
position: inherit;
position: initial;
position: unset;
}
static
默认值,文档流中的位置。
absolute
相对于position的值不为static的第一个祖先元素来定位。
<div>1</div>
<div class="two" style="position: absolute;left: 50px;top: 50px;">2</div>
<div>3</div>
</body>
<script type="text/javascript">
</script>
</html>
<style type="text/css">
div{
height: 100px;
width:200px;
background-color: blue;
opacity: 0.5;
}
</style>
第二个div位置设为abosulte,所以相对于根元素定位。