2017-08-13 145 views
-1

我創建background-image屬性CSS類,我把它放到HTML,但不顯示圖像:爲什麼不顯示背景圖像?

這裏是CSS類:

.showLayers{ 
    background-image: url("http://localhost/mapserver2017/stdicons/GeomindIcons/showLayers.png"); 
    background-repeat: no-repeat; 
} 

.miniToolbarContant{ 
    cursor:pointer; 
    width:20px; 
    height:20px; 
    transition: transform 0.3s; 
} 

這裏是HTML元素:

<button type="button" class="button_air-medium"> 
       <img id="showLayers" class="miniToolbarContant showLayers"/></button> 

但是圖像從未顯示。

而如果我更改HTML上面這樣的:

<button type="button" class="button_air-medium"> 
        <img id="showLayers" class="miniToolbarContant" src="../stdicons/GeomindIcons/showLayers.png"/></button> 

,一切工作正常。

任何想法爲什麼圖像不顯示?

我做錯了什麼?

+2

你爲什麼要用'img'來顯示_background_圖像?首先停止這個廢話。 – CBroe

+0

不敏感圖像的大小爲0,因此除非您指定尺寸,否則它將不可見。 –

+0

你在現場或本地主機上工作嗎? –

回答

1

添加background-size

.showLayers{ 
    background-image: url("http://localhost/mapserver2017/stdicons/GeomindIcons/showLayers.png"); 
    background-repeat: no-repeat; 
    background-size: 20px 20px; 
} 
+0

感謝post.I矩形包裹圖像。任何想法如何刪除它? – Michael

+0

你應該使用''而不是'' –

+0

你的意思是按鈕我應該使用? – Michael

-1

使用按鈕背景圖片不是其子 - IMG

0

在CSS .showLayers只是改變#showLayers

因爲你給的造型一類叫做showLayers CSS,然後在HTML中調用一個名爲showLayers的ID,該ID不存在。

0

它使您的無效文件位置。 在您的第一張img標籤上,您沒有在第二次添加文件的位置。如果你不知道假設我們有四個目錄(一,二,三,四),(三裏面兩臺,裏面一,四里一)
像:

One 
|_Two 
| |_Three 
|_Four 

所以,當你在裏面三你不能訪問目錄一個或兩個或四個。 爲了訪問目錄一,你需要使用../../file_name這裏用../來訪問當前工作目錄的父目錄。