1,position:relative + position:absolute
<!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_box {
position: relative;
}
.sun_box {
position: absolute;
top: 50%;
left: 50%;
margin-left: -50px;
margin-top: -50px;
}
</style>
</head>
<body>
<div style="width: 300px; height: 300px; background: gray" class="father_box clear">
<div style="width: 100px; height: 100px; background: #ffc400" class="sun_box"></div>
</div>
<script></script>
</body>
</html>
2,transform:translate + calc( )
<!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>
.sun_box {
transform: translate(calc((300px - 100px) / 2), calc((300px - 100px) / 2));
}
</style>
</head>
<body>
<div style="width: 300px; height: 300px; background: gray" class="father_box clear">
<div style="width: 100px; height: 100px; background: #ffc400" class="sun_box"></div>
</div>
<script></script>
</body>
</html>
3,margin + .clear
<!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>
.sun_box {
margin-top: 100px;
margin-left: 100px;
}
.clear {
overflow: auto;
zoom: 1;
}
</style>
</head>
<body>
<div style="width: 300px; height: 300px; background: gray" class="father_box clear">
<div style="width: 100px; height: 100px; background: #ffc400" class="sun_box"></div>
</div>
<script></script>
</body>
</html>