码迷,mamicode.com
首页 > 其他好文 > 详细

How to center body on a page?

时间:2017-07-28 11:44:27      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:line   page   like   enter   big   ide   body   技术分享   ica   

?

【提问】

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?

标签:line   page   like   enter   big   ide   body   技术分享   ica   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!