2016-06-25 88 views
1

我想設置一個紋理背景到一個容器div。我的CSS如下:需要幫助設置一個容器div的紋理背景

.container { 
    background-image: url(..img/texture-one.png) repeat; 
} 

我的問題是,圖像沒有顯示出來。如果我在我的HTML中製作img標記,則圖像使用相同的路徑顯示。

+0

你不是說../image代替..image?另外,如果你這樣做,容器將不會根據圖像自動調整大小,所以請確保添加高度/寬度屬性或其他內容。 –

+0

確保url與聲明瞭.container的css文件(或html文件)相關。 – ToddBFisher

回答

1
.container { 
    background-image: url("img/texture-one.png"); 
    background-repeat: repeat-y; 
} 
0

也許只是在圖像鏈接周圍添加引號?

.container { 
    background-image: url("img/texture-one.png"); 
} 
0

你也可以顯示HTML代碼嗎?

如果你在容器中有浮動的元素,那麼容器的高度爲0,所以你看不到東西。在這種情況下,您應該在容器上使用overflow: auto;

0

background-image只能有圖像路徑。

background-image: url|none|initial|inherit;

背景爲多個背景特性的簡寫。

background: bg-color bg-image position/bg-size bg-repeat bg-origin bg-clip bg-attachment initial|inherit;

因此,你需要:

.container { 
    background: url(..img/texture-one.png) repeat; 
}