<!DOCTYPE html>
<html>
<head>
<title>ceshi</title>
</head>
<body>
<div class="box">
<div class="left">
123
</div>
<div class="right">456</div>
</div>
</body>
</html>
<style>
.box{
width: 200px;
height: 200px;
position: absolute;
/*
方法一
left: 0;
right: 0;
top: 0;
bottom: 0;
margin: auto;
*/
/*
方法二
left: 50%;
top: 50%;
margin: -100px 0 0 -100px;
*/
/* 方法三 */
left: 50%;
top: 50%;
transform: translate(-50%,-50%);
background: #4185f3;
}
.left{
display: inline;
}
.right{
float: right;
}
</style>
运行结果如下