简体   繁体   English

如何将页面居中?

[英]How do I center my page?

I realize that the left two containers are not as wide as my div addons but regardless I'd at least like everything to be centered with an even amount of empty space on the left and right of everything. 我意识到左边的两个容器不像我的div addons那么宽,但是不管我至少希望所有内容都居中,并且在所有内容的左侧和右侧都留有均匀的空白空间。 But I can't seem to figure it out. 但我似乎无法弄清楚。 It is a little messy I admit with all of the display: inline-block and float:left I have going on, but even the usual 我承认所有display: inline-block有点混乱display: inline-blockfloat:left我一直在继续,但即使是平常

margin-left:auto
margin-right:auto
width: 600px

isn't of much help to me right now. 现在对我没有太大帮助。 And I'd like to center without setting a random margin-left property that won't render the same at every resolution. 我想居中而不设置一个随机的margin-left属性,该属性不会在每种分辨率下都呈现相同的效果。 Can anyone please assist? 谁能帮忙吗?

The site in question is https://com-bb-dev.com.edu 有问题的网站是https://com-bb-dev.com.edu

Thank you for your expertise. 感谢您的专业知识。

It appears that you are not laying out the page correctly. 看来您没有正确地布置页面。

Consider the following (LOTR reference): 请考虑以下内容(LOTR参考):

  1. One div to contain them all. 一格包含所有内容。
  2. Seven divs for the dwarf-lords floating left (in their halls of stone). 矮人族的七个div向左浮动(在他们的石头大厅中)。
  3. Three divs for the elven kings floating right (under the sky). 精灵王的三个div漂浮在空中(在天空下)。
  4. These divs and more will center on your page (where the shadows lie). 这些div和更多内容将位于您页面的中心(阴影位于此处)。

Center the One div on the page and put the other divs inside this div. 在页面上将一个div居中,然后将其他div放在该div中。

If you just set the #loginPageContainer on the page you linked to width:600px; 如果您仅在链接到的页面上设置#loginPageContainer,则宽度为600px; then it works. 然后就可以了。 Just tried it myself in developer tools. 自己在开发人员工具中尝试过。

It is the wrapper-element that has to be centered. 包装元素必须居中。 Not each div, if there are floated elements on the same "level", it will break. 不是每个div,如果在同一“级别”上有浮动元素,它将中断。

Try this code, just change the values in it so it fit yours 试试此代码,只需更改其中的值即可使其适合您

div {
    width: 100px;
    height: 100px;
    position: absolute;
    left: 0;
    right: 0;
    margin: auto;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM