第一种方法
<style type="text/css">
.first{
width: 500px;
height: 500px;
border: 1px solid black;
margin-left: 50%;
transform: translateX(-50%);
text-align: center;
}
.second{
width: 200px;
height: 200px;
border: 1px solid black;
display: inline-block;
vertical-align: middle;
}
span{
height: 500px;
display: inline-block;
vertical-align: middle;
}
</style>
</head>
<body>
<div class="first">
<span></span>
<div class="second">
</div>
</div>
</body>
第二种方法
<style type="text/css">
.first{
width: 500px;
height: 500px;
border: 1px solid black;
margin-left: 50%;
transform: translateX(-50%);
position: relative;
}
.second{
width: 200px;
height: 200px;
border: 1px solid black;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
}
</style>
</head>
<body>
<div class="first">
<span></span>
<div class="second">
</div>
</div>
</body>
来源:CSDN
作者:cp123153
链接:https://blog.csdn.net/cp123153/article/details/104136689