<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style type="text/css">
*{
padding: 0;
margin: 0;
}
.box{
width: 400px;
height: 400px;
border-radius: 200px;
background-color: #ccc;
margin: 100px auto;
position: relative;
}
.rec{
width: 200px;
height: 200px;
position: absolute;
background-color: red;
/* 定位的百分比参照父容器 */
left: 50%;
top: 50%;
/* 使用transform实现元素居中,百分比参照元素本身的宽高 */
transform: translate(-50%,-50%);
}
</style>
</body>
<div class="box">
<div class="rec"></div>
</div>
</html>