如何在页面中心div? (高度和宽度)? [英] How to center div in the page? (Height & Width)?
本文介绍了如何在页面中心div? (高度和宽度)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
愚蠢的问题,但我找不到答案,因为所有的答案假设中心的div在宽度。
silly question, but I can't find answer on it as all answers assume centering div in terms of width.
我需要的是中心div
What I need is to center div in means of height and width so in a very very center of the page.
我试过这个,但它只是中心div的页面宽度没有高度的方法。
I tried this, but it just centers div in means of page width no height.
#myDiv {
width: 500px;
height: 500px;
margin: auto;
}
那么如何在页面的VERY中心)))
So how can I get it in the VERY center of the page? )))
推荐答案
创建一个包含 wrapper
code> #myDiv 元素,并应用此CSS代码:
Create a wrapper with ID wrapper
around the #myDiv
element, and apply this CSS code:
#wrapper{
display: table;
}
#myDiv{
display: table-cell;
vertical-align: middle; /*Vertically centered*/
text-align: center; /* Horizontally centered */
}
此代码中心任何宽度/高度的元素。
This code centers elements of any width/height.
这篇关于如何在页面中心div? (高度和宽度)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文