为什么top:50%在css不工作? [英] Why is is top:50% in css not working?

查看:520
本文介绍了为什么top:50%在css不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立网站,我要垂直居中:

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;

我的HTML是单个 div / p>

and my HTML is a single div

推荐答案

我认为这应该是有帮助的:)

I think this should be helpful :)

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

<i>center</i>

这篇关于为什么top:50%在css不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆