【提问】

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?的更多相关文章

  1. jquery实现分页功能

    RT,不是很难,但是感觉代码一点都不简洁,就是多加点判断,直接上代码了. HTML部分: <div class = "container-fluid"> <div ...

  2. php多条件搜索

    PHP多条件查询 December : Tuesdayby 小屋 在我们的网站设计过程中,经常会用到多条件查询,本文的源码是一个二手房屋查询的例子.在本例中,我们要实现能够通过地理位置,物业类型,房屋 ...

  3. UWP开发随笔——UWP新控件!AutoSuggestBox!

    摘要 要开发一款优秀的application,控件肯定是必不可少的,uwp就为开发者提供了各种各样的系统控件,AutoSuggestBox就是uwp极具特色的控件之一,也是相对于之前win8.1的ua ...

  4. DeviceFamily XAML Views(一)

    DeviceFamily Veiws 可以为特定的设备(Mobile.Desktop等)制作特定的XAML视图,这种方式可以完全定制XMAL和共享后台代码. 以 Mobile 和 Desktop 为例 ...

  5. js中masonry与infinitescroll结合 形成瀑布流

    后台:(有点问题 page应该从1开始 而不是从0开始)     public function actionExperts()    {        $top=5;        $page=em ...

  6. 发现一php木马代码

    <?php ;//无需验证密码! $shellname='hello~地球~猴子星球欢迎你 '; define('myaddress',__FILE__); error_reporting(E_ ...

  7. [转] Spring MVC sample application for downloading files

    http://www.codejava.net/frameworks/spring/spring-mvc-sample-application-for-downloading-files n this ...

  8. Windows 8.1 应用再出发 - 创建我的第一个应用

    转眼间Windows 8.1已经发布了四个多月,之前因为开发需要对Windows 8.1新特性进行过零散的学习和使用,一直没有静下心来系统的学习过.近日部门有几名新同事加入,需要进行Windows 商 ...

  9. 与众不同 windows phone (52) - 8.1 新增控件: AutoSuggestBox, ListView, GridView, SemanticZoom

    [源码下载] 与众不同 windows phone (52) - 8.1 新增控件: AutoSuggestBox, ListView, GridView, SemanticZoom 作者:webab ...

随机推荐

  1. 如何在Root的手机上开启ViewServer,使得HierachyViewer能够连接(转)

    前期准备: 关于什么是Hierarchy Viewer,请查看官方文档:http://developer.android.com/tools/debugging/debugging-ui.html.个 ...

  2. Eclipse 正则表达式 查找与替换

    CTRL + space in the textboxes gives you all kinds of suggestions for regular expression writing. 查找 ...

  3. 《Go语言实战》摘录:7.2 并发模式 - pool

    7.2 并发模式 - pool

  4. Maven 使用了一个标准的目录结构和一个默认的构建生命周期。

    Maven 使用了一个标准的目录结构和一个默认的构建生命周期. 约定优于配置 当创建 Maven 工程时,Maven 会创建默认的工程结构.开发者只需要合理的放置文件,而在 pom.xml 中不再需要 ...

  5. xcode调试查看变量的值

    对于IPhone开发/XCode的初学者,如何在调试时查看变量的值是很头痛的事情.因为Xcode的expression 经常无法正确显示变量的值.但是强大的GDB可以很方便的帮我们查看变量的值. 当执 ...

  6. UITabBarController 详解之 hidesBottomBarWhenPushed的正确用法

    今天说的是在TabBar嵌套Nav时,进行Push的时候隐藏TabBar的问题. 之前项目也需要这么做,那时候iOS7还没出,也是各种搜罗,后来的解决方法是当push操作的时候自己隐藏Tabbar,p ...

  7. 11i and R12 Table Count in Different Module

    Advertisement Module 11i Tables R12 Tables New Tables AR 551 616 118 BOM 264 337 73 GL 186 309 140 A ...

  8. 详解Java多线程编程中LockSupport

    LockSupport是用来创建锁和其他同步类的基本线程阻塞原语. LockSupport中的park() 和 unpark() 的作用分别是阻塞线程和解除阻塞线程,而且park()和unpark() ...

  9. CentOS 7 在vmware中的网络设置

    一环境说明 二centos在vmware中的安装 三NAT网络设置 四设置固定IP 1修改网卡配置说明 2修改etcresolvconf 实现域名解析 五设置防火墙iptables 1 centos安 ...

  10. 「BZOJ」「3262」陌上花开

    CDQ分治 WA :在solve时,对y.z排序以后,没有处理「y.z相同」的情况,也就是说可能(1,2,3)这个点被放到了(2,2,3)的后面,也就是统计答案在前,插入该点在后……也就没有统计到! ...