简单案例
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.father{
position: relative;
width: 100px;
height: 100px;
background-color: red;
}
.son{
position: absolute;
top: 50px;
left: 50px;
width: 100px;
height: 100px;
background-color: blue;
}
</style>
</head>
<body>
<div class="father">
<div class="son"></div>
</div>
</body>
</html>
定位--半透明遮罩效果
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.father{
position: relative;
width: 600px;
height: 600px;
background-image: url('./641.jpeg');
}
.son{
position: absolute;
bottom: 0px;
width: 600px;
height: 150px;
background-color:rgba(0,0,0,0.5);
}
</style>
</head>
<body>
<div class="father">
<div class="son"></div>
</div>
</body>
</html>
子绝父相--垂直居中案例
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
.father{
position: relative;
width: 200px;
height: 200px;
background-color: pink;
}
.son{
position: absolute;
left:50%;
top: 50%;
transform: translate(-50%,-50%);
width: 100px;
height: 50px;
background-color: blue;
}
</style>
<body>
<div class="father">
<div class="son"></div>
</div>
</body>
</html>
二维码居中案例
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
*{
margin: 0px;
padding: 0px;
}
div{
float: left;
/* display:inline-block; */
width: 270px;
height: 50px;
text-align: center;
line-height: 50px;
border: 1px solid gray;
}
.a{
width: 358px;
}
.b1{
position: relative;
}
img{
position: absolute;
top: 50px;
left: 50%;
transform: translateX(-50%);
width: 100px;
height: 100px;
}
</style>
<body>
<div class="a">我要投资</div>
<div>平台介绍</div>
<div>新手专区</div>
<div class="b1">手机微金所 <img src="641.jpeg"/></div>
<div class="a">个人中心</div>
</body>
</html>