2012-06-12 146 views
12

如何在Opera上設置background-position-x?如何設置背景位置x?

div#logocontainer{ 
    width: auto; 
    height: auto; 
    text-align: center; 
    line-height: 200px; 
    overflow: auto; 
    margin-left: auto; 
    margin-right: auto; 
    background-image: url(../img/WatermarkMP.png); 
    background-repeat: no-repeat; 
    background-position-x: 50%; 
    background-position-y: 50%; 
    padding: 10px; 
} 

我有以下的CSS規則,它會在Chrome和Safari,桌面和移動版本上正確顯示。但它不會在Opera上工作,似乎不支持background-position-x:50%; background-position-y:50%;規則。我是否必須編寫腳本才能與Opera兼容?我如何解決這個問題以支持歌劇呢?

它也似乎不圓jQuery Mobile的角落...

+0

它在Firefox上工作嗎? – JAB

+0

@JAB:不,它沒有。 – thirtydot

回答

22

你必須設置background-position: 50% 50%。這些-x-y屬性僅在Internet Explorer和Webkit瀏覽器中受支持。

+0

這是爲什麼?據我所知,這種類型的大多數其他複合屬性可以在所有系統中分解成它們的組成部分(比如'margin-left','margin-right','margin-top'和'margin' -bottom')。 – JAB

+0

謝謝!所以正確的方法是隻使用背景位置?或者其他瀏覽器需要-x -y嗎? – Astronaut

+6

background-position:50%50%;在每個瀏覽器上工作,忘記-x -y,如duri所說,他們沒有廣泛支持 – Luca