2013-01-31 48 views
0

我想升級我的網站模板。 我想要的內容是在一個固定寬度居中div。這不是問題,網上有很多例子。 由於我已經滿足文本&表,我想確保div不會削減某些頁面的內容。 我不想用Javascript來調整寬度。 有沒有辦法做到這一點與div或應該使用表呢?固定寬度的頁面佈局,但隨內容可調

回答

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; 
} 

的內容將不會被裁剪,除非和直到你在同一時間

+0

只有中心寬度使用fixed width divoverflow: hidden;,但主要的問題是當內容是調整寬度太大(例如:大表或大圖) – Joe

+0

使用固定寬度的div和'margin:auto;'它會將事情集中起來,因爲內容大於容器,請使用overflow:auto; –

相關問題