如何将页面居中以允许两侧背景?

时间:2013-02-08 21:35:43

标签: css html background alignment

我所说的如下:

html {
    background: url(../Images/bgplaid.jpg);
    background-repeat: inherit;
    margin: 0px;
    padding: 0px;
    margin-top: 0px;
    padding-top: 0px;
    width: 1024px;      
}

该css将页面大小设置为1024px,因此大多数屏幕都较大,1024px的外部是背景图像。

我想知道的是如何使页面居中,以便始终保持在中心位置。目前它位于左侧。背面只显示在右边。我想知道如何以html为中心。

我尝试将div放入align='center'并尝试包含div和float center。没有骰子。

2 个答案:

答案 0 :(得分:4)

使用margin: 0px auto;

html {
    background: url(../Images/bgplaid.jpg);
    background-repeat: inherit;
    margin: 0px auto;
    padding: 0px;
    margin-top: 0px;
    padding-top: 0px;
    width: 1024px;      
}

答案 1 :(得分:0)

将身体后面的所有内容放入带有ID包装器<html><body><div id="wrapper">YOUR HTML CODE</div></body></html>

的div中
#wrapper {
width: 1024px;
margin: 0 auto;
}