第三种解决方案
#parent {
width: 200px;
height: 600px;
background: #ccc;
position: absolute;
}
#child {
width: 200px;
height: 200px;
background: #c9394a;
position: absolute; left: 0; top: 0; right: 0; bottom: 0;
margin: auto 0;
#parent {
width: 200px;
height: 600px;
background: #ccc;
position: absolute;
}
#child {
width: 200px;
height: 200px;
background: #c9394a;
position: absolute; left: 0; top: 0; right: 0; bottom: 0;
margin: auto 0;
2019-11-10
第三种解决方案
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>测试</title>
<style>
.main{
width:100px;
height:500px;
background: #666;
display: flex;
align-items: center;
}
.child {
width:100px;
height:100px;
background: red;
}
</style>
</head>
<body>
<div class="main">
<div class="child">
11111
1111111111
11111111111
11111111
</div>
</div>
</body>
</html>
举报