2015-03-02 58 views
2

我試圖將視頻對準圖像中心。將視頻嵌入圖像中心

.vbackground { 
 
    background-image: url('http://s1.postimg.org/hdo0xh2of/image.png'); 
 
    background-repeat: no-repeat; 
 
    width: 600px; 
 
    height: 600px; 
 
    position: relative; 
 
} 
 
#match { 
 
    position: absolute; 
 
    top: 0; 
 
    bottom: 0; 
 
    left: 0; 
 
    right: 0; 
 
    margin: auto; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<div class='vbackground'> 
 
    <video controls id='match' width='300' height='300'> 
 
    <source src='match.mp4' type="video/mp4" /> 
 
    </video> 
 
</div>

我如何才能讓在圖像的中心(從四面八方)的視頻?它目前在圖像底部對齊。

回答

0

只需加上margin-left:automargin-right: auto;到您的#match CSS樣式,它會將視頻對齊到圖像的中心。


 
#match { 
 

 
    margin-left: auto; 
 
    margin-right: auto; 
 

 
}

1

嘗試刪除從match ID選擇position: absolute規則和對.vbackgroundtext-align屬性設置爲center
這應該工作 -

.vbackground { 
    background-image: url('http://s1.postimg.org/hdo0xh2of/image.png'); 
    background-repeat: no-repeat; 
    width: 600px; 
    height: 600px; 
    position: relative; 
    text-align: center; 
}  
#match { 
    /*position: absolute;*/ 
    top: 0; 
    bottom: 0; 
    left: 0; 
    right: 0; 
    margin: auto; 
} 
+0

只是意識到使用'文本對齊:中心;'規則用於定位的圖像不建議(見http://stackoverflow.com/questions/7055393/center-image - 使用 - 文本對齊中心?RQ = 1)。您可以改爲將.vbackground的寬度和高度設置爲原始圖像的大小,即分別爲594px/372px。 – 2015-03-02 15:42:24