<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>
        *{
            margin:0;
            padding:0;
        }
        .cc{
            display: table;
            width:300px;
            height:300px;
            margin:30px auto;
            text-align:center;
            background:#00c1de;
        }
        p{
            display:table-cell;
            background:green;
            vertical-align:middle;
        }
    </style>
</head>
<body>
<div class="cc">
    <p>1111</p>
</div>
</body>
</html>

给父元素设置display:table     子元素设置display:table-cell;vertical-align:middle

如果需要需要让不定高的图片垂直居中,则需要给父元素设置

  1. display: flex;
  2. justify-content: center;
  3. align-items: center;

相关文章:

  • 2021-10-23
  • 2021-10-14
  • 2021-08-27
  • 2021-05-27
  • 2021-07-26
  • 2022-12-23
  • 2021-09-30
  • 2022-01-13
猜你喜欢
  • 2021-08-13
  • 2022-01-23
  • 2021-09-11
  • 2022-02-13
  • 2022-12-23
  • 2021-06-09
  • 2022-01-14
相关资源
相似解决方案