css布局之水平垂直居中

2019-10-16  本文已影响0人  行走的蛋白质

<style>
  .outer {
    height: 800px;
    width: 1200px;
    background-color: #dfdfdf;
  }
  .inner {
    width: 100px;
    height: 50px;
    background-color: #999;
  }
</style>
<body>
  <div class="outer">
    <div class="inner"></div>
  </div>
</body>
  .outer {
    position: relative;
  }
  .inner {
    position: absolute;
    top: 50%;
    left: 50%;
    margin-top: -25px;
    margin-left: -50px;
  }
  .outer {
    position: relative;
  }
  .inner {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    margin: auto;
  }
  .outer {
    position: relative;
  }
  .inner {
    position: absolute;
    top: 50%;
    left: 50%;
    /*transform: translate(-50px, -25px);*/
    transform: translate(-50%, -50%);
  }
.outer {
    display: flex;
    justify-content: center;
    align-items: center;
  }
  .outer {
    display: table-cell;
    vertical-align: middle;
    text-align: center;
  }
  .inner {
    display: inline-block;
  }
上一篇 下一篇

猜你喜欢

热点阅读