2013-07-22 25 views
0

我有一個div標籤內我的視頻,我 水平居中的窗口如何中心內的視頻垂直

.center { margin: 0 auto; width: 720px; height: 480px; } 

我一直在試圖與

垂直居中它的窗口
.center { margin: 0 auto 0 auto; width: 720px; height: 480px; } 

它不起作用。

任何想法?

+1

垂直於什麼?窗戶?此外,它的「高度:480px」。 – BenM

+1

'height = 480px; != height:480px;'也有一些html和[jsfiddle](http://jsfiddle.net)會很好。 – Dom

+0

謝謝,我的錯誤,輸入了錯誤 –

回答

4

您可以使用絕對定位輕鬆完成此操作。例如(將其中心到容器):

.center { 
    width: 720px; 
    height: 480px; 
    position: absolute; 
    top: 50%; 
    left: 50%; 
    margin: -240px 0 0 -360px; 
} 

基本上,將其指定爲從容器的左上角爲50%,然後指定其是一半高度和寬度分別緣陰性。

請參閱本jsFiddle Demo

0

如果您是使用absolute一個常見的做法是:

.center { 
    width: 720px; 
    height: 480px; 
    position: absolute; 
    top: 0; 
    bottom:0; 
    left: 0; 
    right:0; 
    margin: auto; 
} 

這將是中心,它的容器。