0

我想升级我的网站模板。我希望内容位于固定宽度的居中 div 中。这不是问题,网上有很多例子。由于我已经对文本和表格感到满意,因此我想确保 div 不会剪切某些页面的内容。我不想使用 Javascript 来调整宽度。有没有办法用 div 来做到这一点,或者我应该使用 table 来代替?

4

1 回答 1

0

没有让你的问题正确,也像垂直一样居中?如果你想要它垂直居中而不是你需要使用position: absolute;,如果你想要它水平居中你只需要使用margin: auto;,就这么简单......

/* Totally center fixed width content */

.center {
   position: absolute;
   top: 50%;
   left: 50%;
   margin-top: /* Half of the total height of the container div */
   margin-left: /* Half of the total width of the container div */
}

如果您需要内容水平居中,则需要使用

.horizontal {
   margin: auto;
}

除非您同时使用fixed width divand ,否则内容不会被裁剪overflow: hidden;

于 2013-01-31T13:53:21.350 回答