CSS:绝对定位、相对定位、固定定位( 二 )


left: 100px;*/
}
.box{
width: 200px;
height: 200px;
background-color: blue;
 
position: absolute;
right: 0px;
bottom:0px;
}
.box-one{
width: 400px;
height: 400px;
background-color: red;
}
/*.box2{
width: 400px;
height: 400px;
background-color: red;
}*/
</style>
</head>
<body>
<div class="box-father">
<div class="box-one">
 
</div>
<div class="box">
 
</div>
</div>
<!--<div class="box2">
 
</div>-->
</body>
</html>
固定定位(fixed)代码案例:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>固定定位</title>
<style type="text/css">
/*固定定位:
*1、脱离了文档流
*2、原点计算:按浏览器(0,0)来作为基准
*/
*{
padding: 0px;
margin: 0px;
}
body{
height: 1800px;
background-image: url(img/logo.png);
}
.box-father{
width: 500px;
height: 500px;
background-color: yellow;
position: relative;
}
.box{
width: 200px;
height: 200px;
background-color: blue;
/*固定定位*/
position: fixed;
right: 0px;
bottom: 0px;
}
</style>
</head>
<body>
<div class="box-father">
<div class="box">
 
</div>
</div>
</body>
</html>
 

CSS:绝对定位、相对定位、固定定位

文章插图
 

【CSS:绝对定位、相对定位、固定定位】


推荐阅读