我的网页上有一个主div,其属性为align="center"
,但由于某种原因,它没有在中心对齐。
供参考here is the page。
CSS:
#page{
background-color: #4C1B1B;
width:85%;
height:500px;
}
HTML:
<body>
<div id="page" align="center">
<div id="pageleft">
TEST
</div>
<div id="pageright">
</div>
</div>
</body>
提前致谢!
答案 0 :(得分:2)
将margin:auto
添加到#page
规则,然后移除align="center"
#page{
background-color: #4C1B1B;
width:85%;
height:500px;
margin:auto;
}
答案 1 :(得分:1)
To completely centre align the div, the following formula can be applied
left = (100 - (width of the div))/2
Using Jquery this can be done as below
var left = (100 - 85)/2;
$("#page").css("left",left + "%")