一个position为fixed的div,宽高自适应,怎样让它水平垂直都在窗口居中?

.div{
    position: fixed;
    left: 50%;
    top: 50%;
    -webkit-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
}
<div id="flex-wrap">
    <div class="x"></div>
</div>
style
#flex-wrap {
   1000px;
  height: 300px;
  border: 1px solid red;
  margin: 0 auto;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
}
.x {
   100px;
  height: 100px;
  background: red;
}
原文地址:https://www.cnblogs.com/chenxiaomeng/p/6563920.html