How to center body on a page?
【提问】
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?的更多相关文章
- jquery实现分页功能
RT,不是很难,但是感觉代码一点都不简洁,就是多加点判断,直接上代码了. HTML部分: <div class = "container-fluid"> <div ...
- php多条件搜索
PHP多条件查询 December : Tuesdayby 小屋 在我们的网站设计过程中,经常会用到多条件查询,本文的源码是一个二手房屋查询的例子.在本例中,我们要实现能够通过地理位置,物业类型,房屋 ...
- UWP开发随笔——UWP新控件!AutoSuggestBox!
摘要 要开发一款优秀的application,控件肯定是必不可少的,uwp就为开发者提供了各种各样的系统控件,AutoSuggestBox就是uwp极具特色的控件之一,也是相对于之前win8.1的ua ...
- DeviceFamily XAML Views(一)
DeviceFamily Veiws 可以为特定的设备(Mobile.Desktop等)制作特定的XAML视图,这种方式可以完全定制XMAL和共享后台代码. 以 Mobile 和 Desktop 为例 ...
- js中masonry与infinitescroll结合 形成瀑布流
后台:(有点问题 page应该从1开始 而不是从0开始) public function actionExperts() { $top=5; $page=em ...
- 发现一php木马代码
<?php ;//无需验证密码! $shellname='hello~地球~猴子星球欢迎你 '; define('myaddress',__FILE__); error_reporting(E_ ...
- [转] Spring MVC sample application for downloading files
http://www.codejava.net/frameworks/spring/spring-mvc-sample-application-for-downloading-files n this ...
- Windows 8.1 应用再出发 - 创建我的第一个应用
转眼间Windows 8.1已经发布了四个多月,之前因为开发需要对Windows 8.1新特性进行过零散的学习和使用,一直没有静下心来系统的学习过.近日部门有几名新同事加入,需要进行Windows 商 ...
- 与众不同 windows phone (52) - 8.1 新增控件: AutoSuggestBox, ListView, GridView, SemanticZoom
[源码下载] 与众不同 windows phone (52) - 8.1 新增控件: AutoSuggestBox, ListView, GridView, SemanticZoom 作者:webab ...
随机推荐
- RabbitMQ简单使用
环境搭建: RabitMQ是用Elang编写的,虽然Elang本身是跨平台的,但也同时意味着搭建Rabit环境需要首先配置Elang环境.配置RabitMQ的网上教程还比较多的: windows 下 ...
- 利用webBrowser获取页面iframe中的内容
1.获取frame的document HtmlDocument htmlDoc = webBrowser1.Document; htmlDoc = webBrowser1.Document.Wind ...
- Java 中 byte、byte 数组和 int、long 之间的转换
Java 中 byte 和 int 之间的转换源码: //byte 与 int 的相互转换 public static byte intToByte(int x) { return (byte) x; ...
- 该对象尚未初始化。请确保在所有其他初始化代码后面的应用程序启动代码中调用 HttpConfiguration.EnsureInitialized()。
WebAPI使用属性路由,配置config.MapHttpAttributeRoutes();后出现错误: System.InvalidOperationException: 该对象尚未初始化.请确保 ...
- Managing DbContext the right way with Entity Framework 6: an in-depth guide by mehdime
UPDATE: the source code for DbContextScope is now available on GitHub: DbContextScope on GitHub. A b ...
- xcode 不能选择模拟器
重新安装了xcode后,程序无法运行,不能选择模拟器 或者 设备? 1.你之所以选择不了模拟器或者设备,是因为你工程中的iOS Deployment Target设置不对.比如你装的是xcode4.0 ...
- arcmap搜索脚本错误
C盘/windows/temp,将temp文件夹右键单击,选择属性>选择安全>编辑>AlL APPLICATION PACKAGES>确定>关闭,如是操作即可解决 在cu ...
- cloudera项目源代码
以下项目都需要安装git,Linux的git还是比较容易安装的,windows的git安装参考项目区域:软件版本控制-在Windows中使用Git视频介绍 git相关软件安装参考win7安装 git软 ...
- 用开源项目FlipImageView实现图片的翻转效果
开源项目地址:https://github.com/castorflex/FlipImageView 本实例我没做什么改动,就是添加了注释,方便大家阅读.和之前一样,导入library和工程 ...
- 低版本系统兼容的ActionBar(三)自定义Item视图+进度条的实现+下拉导航+透明ActionBar
一.自定义MenuItem的视图 custom_view.xml (就是一个单选按钮) <?xml version="1.0" encoding="u ...