2013-12-12 62 views

回答

0

你可能會遇到其他問題。具有margin:auto和另一個寬度較寬的塊元素中的設置寬度的塊元素將居中,即使容器比視口寬。

.hooge-div{ 
    width: 2000px; 
    background: #eee; 
    height: 50px; 
} 

.small-one{ 
    width: 50px; 
    margin: 0 auto; 
    background: #111; 
    height: 20px; 
} 

http://jsfiddle.net/EW7Wy/

0

使用自動利潤率左緣和右只需要在觀點尺寸考慮如果父DIV不具有特定的寬度。

例如,父DIV以下具有特定的寬度和子是基於該特定寬度居中:

<div style="width: 1200px; background: blue;"> 
    <div style="margin: 0 auto; width: 50px; background: red;"> 
     I am the child div. 
    </div> 
</div> 
相關問題