首页 > 其他 > 详细

How to center body on a page?

时间:2017-07-28 11:39:22      阅读:285      评论:0      收藏:0      [点我收藏+]

?

【提问】

I‘m trying to center the body element on my HTML page.

技术分享

Basically, in the CSS I set the body element to be?display: inline-block;?so that it is only as wide as its contents. That works fine. However,?margin: 0px auto;?doesn‘t center it on the page.

Does anyone know how to fix this? I want the big blue square to be centered on the page, not floating to the left like it is now.

Here‘s my CSS:

body {

display: inline-block;

margin: 0px auto;

text-align: center;

}

?

【回答】

Also apply text-align: center; on the html element like so:

html {

  text-align: center;

}
					

A better approach though is to have an inner container div, which will be centralized, and not the body.

How to center body on a page?

原文:http://www.cnblogs.com/time-is-life/p/7249294.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!