I presume the answer to this question is really simple but i am stumped.

I am trying to get a website positioned in the center of the screen like the Guardian website - http://www.guardian.co.uk/ 。我认为我使用左右边框是正确的,但是这使得定位页脚变得困难。

查看了 Guardian 网站并使用了 firefox 检查元素功能,看来他们在屏幕的左侧和右侧都没有使用 div。事实上,容器似乎只是在屏幕的中间。

所以我想我的问题是。你如何定位这样的容器?

最佳答案

.container {
    /* remember to set a width */
    margin-right: auto;
    margin-left: auto;
}

这是 fiddle :http://jsfiddle.net/d9yBs/

您还可以组合到 2 个边距属性,并使用简写:
margin: 0 auto;

这会将顶部和底部边距设置为 0,将左右边距设置为自动。

关于html - 如何在屏幕中间放置一个容器?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14402038/

10-12 02:23