Why is is top:50% in css not working?

后端 未结 7 1753
野性不改
野性不改 2021-02-03 22:30

I am making a website and I\'m trying to vertically center:

 position: absolute;
 width:1200px;
 height:600px;
 top: 50%;
 left: 50%;
 margin-left: -600px;
         


        
7条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-03 22:44

    top:50%; works fine, but wont "center" the item, it will place it's top edge 50% of the page's height from the top. Similarly to how you have margin-left:-600px; you should also add margin-top:-300px;

提交回复
热议问题