<html>
<head>
<title></title>
<style type="text/css">
#p1{width: 300px;height: 200px;background-color: blue;position: absolute;}
#p2{width: 50px;height: 50px;background-color: red;margin: 0 auto;position: absolute;bottom:20px;}
</style>
</head>
<body>
<p id="p1">
<p id="p2"></p>
</p>
</body>
</html>
This method is more suitable for situations where the width and height of itself and the width and height of the container are unclear
Additionally, I have summarized several centering methods:
Final effect
Set the left value
Don’t know how to search? You can find the answer by searching in the community, so why repeat so many questions.
@_qunshan_
@_qunshan_’s answer