如何将整个html体与中心对齐? [英] How to align entire html body to the center?
问题描述
如何将整个html体对齐到中心?
How do I align entire html body to the center ?
推荐答案
我刚刚偶然发现这个旧帖子, 'm肯定user01早已找到他的答案,我发现当前的答案不太好工作。使用其他人提供的信息玩了一会儿后,我发现了一个解决方案,在IE,Firefox和Chrome的工作。在CSS中:
I just stumbled on this old post, and while I'm sure user01 has long since found his answer, I found the current answers don't quite work. After playing around for a little bit using info provided by the others, I found a solution that worked in IE, Firefox, and Chrome. In CSS:
html, body {
height: 100%;
}
html {
display: table;
margin: auto;
}
body {
display: table-cell;
vertical-align: middle;
}
这几乎与abernier的答案相同,但我发现包括宽度会破坏对中,如省略汽车保证金一样。我希望任何人谁绊倒这个线程会发现我的答案有帮助。
This is almost identical to abernier's answer, but I found that including width would break the centering, as would omitting the auto margin. I hope anyone else who stumbles on this thread will find my answer helpful.
注意:省略 html,body {height:100%; }
只能水平居中。
Note: Omit html, body { height: 100%; }
to only center horizontally.
这篇关于如何将整个html体与中心对齐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!