【问题标题】:Is there a way to position a html element absolute but still place it in the center of the page? [duplicate]有没有办法将 html 元素绝对定位但仍将其放置在页面的中心? [复制]
【发布时间】:2020-02-17 11:00:56
【问题描述】:

 .container{
   position: absolute;
   margin: 0 auto;// this doesn't position it in the centre anymore.
 }
<div class="container">
   this is a container
</div>

“这应该是放在中间的……但是当我把它定位为绝对时,它又回到了网页的顶部。有没有办法绕过这个。”

【问题讨论】:

    标签: html css debugging


    【解决方案1】:

    这样就可以了:

     .container{
       position: absolute;
       top: 50%;
       left: 50%;
       transform: translate(-50%,-50%);
     }
    

    【讨论】:

      猜你喜欢
      • 2019-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-04
      • 1970-01-01
      • 2020-12-17
      • 1970-01-01
      • 2020-12-29
      相关资源
      最近更新 更多