一个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 {
  width: 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 {
  width: 100px;
  height: 100px;
  background: red;
}

 

posted @ 2017-03-17 09:16  陈晓猛  阅读(3652)  评论(0编辑  收藏  举报