Html div id 未正确对齐

发布于 2024-12-27 22:47:42 字数 549 浏览 3 评论 0原文

我的页面上有一个主 div 具有属性 align="center",但由于某种原因它没有在中心对齐。

供参考这里是页面

CSS:

#page{
    background-color: #4C1B1B;
    width:85%;
    height:500px;

}

HTML:

<body>
   <div id="page" align="center">
      &nbsp;
      <div id="pageleft">
        TEST
      </div>
      <div id="pageright">
        &nbsp;
      </div>
  </div>
</body>

提前致谢!

I have a main div on my page that has the attribute align="center", yet for some reason it is not aligning in the center.

for reference 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>

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情丝乱 2025-01-03 22:47:42

margin:auto 添加到 #page 规则中,并删除 align="center"

#page{
   background-color: #4C1B1B;
   width:85%;
   height:500px;
   margin:auto;
}

Add margin:auto to the #page rule instead and remove the align="center"

#page{
   background-color: #4C1B1B;
   width:85%;
   height:500px;
   margin:auto;
}
夏夜暖风 2025-01-03 22:47:42
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 + "%")
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 + "%")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文