1.static定位
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
.wrapper{
width: 600px;
height: 600px;
background-color: antiquewhite;
border: 20px blueviolet solid;
box-sizing: content-box;
}
.a, .b, .c{
width: 150px;
height: 150px;
font-size: 24px;
}
.a{
background-color: aqua;
}
.b{
background-color: #1515ff;
}
.c{
background-color: #ff5715;
}
</style>
</head>
<body>
<div class="wrapper">
<div class="a">A</div>
<div class="b">B</div>
<div class="c">C</div>
</div>
</body>
</html>
2.relative定位
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
.wrapper{
width: 600px;
height: 600px;
background-color: antiquewhite;
border: 20px blueviolet solid;
box-sizing: content-box;
}
.a, .b, .c{
width: 150px;
height: 150px;
font-size: 24px;
}
.a{
background-color: aqua;
position: relative;
top: 50%;
left: 50%;
margin-top: -75px;
margin-left: -75px;
}
.b{
background-color: #1515ff;
}
.c{
background-color: #ff5715;
}
</style>
</head>
<body>
<div class="wrapper">
<div class="a">A</div>
<div class="b">B</div>
<div class="c">C</div>
</div>
</body>
</html>
3.absolute定位
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
.wrapper{
width: 600px;
height: 600px;
background-color: antiquewhite;
border: 20px blueviolet solid;
box-sizing: content-box;
position: relative;
}
.a, .b, .c{
width: 150px;
height: 150px;
font-size: 24px;
}
.a{
background-color: aqua;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
margin: auto;
}
.b{
background-color: #1515ff;
}
.c{
background-color: #ff5715;
}
</style>
</head>
<body>
<div class="wrapper">
<div class="a">A</div>
<div class="b">B</div>
<div class="c">C</div>
</div>
</body>
</html>
4.fixed定位
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
.wrapper{
width: 600px;
height: 600px;
background-color: antiquewhite;
border: 20px blueviolet solid;
box-sizing: content-box;
}
.a, .b, .c{
width: 150px;
height: 150px;
font-size: 24px;
}
.a{
background-color: aqua;
position: fixed;
right: 0;
top:50%;
margin-top: -75px;
}
.b{
background-color: #1515ff;
}
.c{
background-color: #ff5715;
}
</style>
</head>
<body>
<div class="wrapper">
<div class="a">A</div>
<div class="b">B</div>
<div class="c">C</div>
</div>
</body>
</html>