如何将div从上到下居中? [英] How to center a div from top to bottom?
问题描述
我只希望div位于页面的中心,从上到下的间距相等,我需要使用百分比,因为div的内容不一样。我尝试了底部:50%,但这是行不通的。
伙计们,谢谢你的答案!我的有点不同,这是我的错误,没有添加这个,请访问我的博客来查看问题。
大家好,感谢您花时间回答这样一个愚蠢的问题,但我发现最简单的方法就是使用填充:
padding-top:X%;
padding-bottom:X%;
然后把它弄糟看看你的结果是什么。如果你有什么更好的做法请分享,因为这显然不是最可靠的。
position:absolute;
top:20%; bottom:20%
}
另见了解垂直对齐。
I just want the div to be in the center of the page, equal spacing from top to bottom and I need to use percents because the div content varies. I tried bottom:50% but this does not work.
Hey guys, thanks for the answers! Mine's a little different and it is my mistake for not adding this, visit my blog to view the issue.
Hey everyone, thanks for using your time to answer such a stupid question, but I found that the easiest way is to just use padding:
padding-top:X%;
padding-bottom:X%;
Then just mess with it to see what your result is. If you have anything better PLEASE DO SHARE because this is obviously probablly not the most reliable.
#mydiv {
position:absolute;
top:20%; bottom:20%
}
See also Understanding Vertical Align.
这篇关于如何将div从上到下居中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!