小div在大div中垂直居中方式

  代码:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>div居中</title>
  <style>
       * {
            margin:0;
            padding:0;
          }
          .content {
            width:400px;
            height:400px;
            background:orange;
            border: 1px solid green;
            position:relative;
            margin: 100px auto;
          }
          .nav {
            width:80px;
            height:80px;
            line-height:80px;
            text-align:center;
            background:green;
            margin: auto;
            position:absolute;
            left: 0;
            top: 0;
            bottom:0;
            right: 0;
          }
  </style>
</head>
<body>
  <div class="content">
         <div class="nav">这是内容</div>
    </div>
</body>
</html>

  效果:

 

posted @ 2019-10-28 18:30  码农下的天空  阅读(726)  评论(1编辑  收藏  举报
点击这里给我发消息
在线沟通 返回顶部
欢迎关注公众号

惊风随笔