一個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;
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM