1

當我把下列一個divbody,這個工程:CSS失敗 - 背景位置,背景重複,背景大小,背景附件

<div style="display: block; width:100%; height: 100%; min-height: 100vh; background-color: #FFFFFF; background: url(./images/pic.jpg); background-position: center; background-repeat: no-repeat; background-size: cover; background-attachment: fixed;"> 

但是當我使用的CSS不工作:

<style type="text/css" media="all"> 
.myMainDiv { 
    width:100%; 
    height: 100%; 
    min-height: 100vh; 
    background-color: #FFFFFF; 
    background-position: center; 
    background-repeat: no-repeat; 
    background-size: cover; 
    background-attachment: fixed; 
} 
</style> 

<div class="myMainDiv" style="display: block; background: url(./images/pic.jpg);"> 

這似乎是想錯了,因爲我需要爲每個背景不同的PIC,然後這導致background-repeat等被忽略。 (注意:不同的div也會有不同的顯示值,無論是塊還是無,因此它們也需要單獨聲明,但這不是問題。)

任何人都知道爲什麼以及是否有解決方法。

+0

包含'.myMainDiv {...}'在''之間嗎? – Banzay

+0

你把它放在