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.

时间: 2024-08-08 01:36:17

How to center body on a page?的相关文章

jsp-简单小程序(乘法表、)

乘法表 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.

抄袭的用Jsp+JavaBean+Mysql实现的登录和注册

用Jsp+JavaBean+Mysql实现的登录和注册 (2010-11-18 20:54:43) 转载▼ 标签: 软件   共同学习和进步:一个简单的用户登录和注册系统. 代码比较简单,希望对刚开始学习的同学有所帮助. 具体代码如下: *******用户注册页面 <%@ page language="java" import="java.util.*" pageEncoding="gbk"%><html>  <he

Hibernate+SpringMVC+Spring+分页实现留言管理项目

项目结构: 这里使用到了Mysql数据库 所用到的包:略. 首先进行springmvc.xml的配置,注意数据库密码要改为自己的. <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema

dev 官网

https://www.devexpress.com/Support/Center/Example/Details/E1343 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication15.WebForm1" %> <%@ Register Assembly=&quo

【Win10】开发中的新特性及原有的变更

声明:本文内容适用于 Visual Studio 2015 RC 及 Windows 10 10069 SDK 环境下,若以后有任何变更,请以新的特性为准. 一.Password 控件的小眼睛属性的变更 在 Windows 8.1(含 Windows 8) 及 Windows Phone 8.1 Runtime 中,Password 控件的小眼睛是由 IsPasswordRevealButtonEnabled 属性定义的,但是,尽管是相同的属性名字,却有着不同的表现形式. Windows 8.1

Android Launcher3的DeviceProfile的改变

最近真忙,没时间细写blog了. 对比了两个平台的Launcher3项目,虽然都是3,但是代码也不是一成不变的,新版本的Launcher3,DeviceProfile也从DynamicGrid中独立出来了. 之前加的很多属性不再适用,需要重新阅读源码,进行修改.呃,工作量不小. DeviceProfile.java /* * Copyright (C) 2008 The Android Open Source Project * * Licensed under the Apache Licen

Ext LayOut

ExtJs FormPanel布局 ExtJS中layout的12种布局风格 extjs的容器组件都可以设置它的显示风格,它的有效值有 absolute, accordion, anchor, border, card, column, fit, form and table.  一共9种. 另外几种见:  http://www.sencha.com/deploy/dev/examples/layout-browser/layout-browser.html  里面有详细的例子. ·  abso

PHPCMS常见问题

(1)调用会员头像: {get_memberavatar($r['userid'],1,45)} 只要能够调用到userid,那么这段代码在哪里都可以使用:首页.栏目页.文章页.  这里我就用get来调用member表里面的userid字段. /*这里就可以获取到userid*/ {pc:get sql="select * from v9_member order by regdate desc" num="6"} {loop $data $r}          

php多条件搜索

PHP多条件查询 01 December 2009 0:54 Tuesdayby 小屋 在我们的网站设计过程中,经常会用到多条件查询,本文的源码是一个二手房屋查询的例子.在本例中,我们要实现能够通过地理位置,物业类型,房屋价格,房屋面积及信息发布日期等多个条件查询到客户所需的资料. 查询文件(search.php) 一.生成查询语句: <? $conn=mysql_connect("localhost","root",""); $db=my