2017-10-16 243 views
1

圖片無法顯示在我的頁面中。背景圖片未加載

<div class="rating" style="width:25%;float:right;height:100px"> 
     <span class="truckIcon"> 
     <!-- <img src="../images/logo/favicon.png"> 
     </span> --> 
</div> 

CSS:

.truckIcon{ 
    background-image: url(../images/icons/favicon.png);no-repeat !important; 
    width:80px; 
    height:80px; 
} 

這是我的CSS路徑:\ulmt\html\css\style.css
這是我的圖片路徑:\ulmt\html\images\icons\favicon.png

有什麼不對嗎?

+0

它應該閱讀背景:網址(「...」)不重複重要或添加背景重複:不重複的背景圖像 – slashsharp

+0

是一個內聯元素。無論是塊級元素還是內聯塊 – Krishna9960

回答

1

您已經使用了span元素,這是一個內聯元素。所以你的寬度和高度不會被應用在它上面。爲了使它工作,添加一個名爲display:inline-block的屬性;

.truckIcon{background-image: url(../images/icons/favicon.png)no-repeat !important; 
    width:80px; 
    height:80px; 
    display: inline-block; 
} 
+0

@JoostS我可以看看你做的工作嗎? – Krishna9960

+0

只需點擊我的個人資料... – JoostS

+0

我沒有得到你想說的 – Krishna9960

2

只是在不重複前刪除分號。風格應該是

.truckIcon{background-image: url(../images/icons/favicon.png)no-repeat !important; 
 
    width:80px; 
 
    height:80px; 
 
}

2

刪除分號;之前no-repeat從圖像的URL在你的CSS,如:

.truckIcon { 
    background-image: url(../images/icons/favicon.png) no-repeat !important; 
    width:80px; 
    height:80px; 
} 

希望這有助於!

3

.truckIcon是線元素,讓你需要添加display:inline-block爲一件事情background-imageno-repeat工作,讓你需要添加background-repeat: no-repeat !important;

.truckIcon{ 
    background-image: url(../images/icons/favicon.png); 
    background-repeat: no-repeat !important; 
    width:80px; 
    height:80px; 
    display: inline-block; 
} 
2

跨度是一個內聯元素。所以你需要風格顯示:塊;或顯示:inline-block; 還要取消你的親密span標籤img標籤

.truckIcon{ 
    background-image: url(../images/icons/favicon.png)no-repeat !important; 
    width:80px; 
    height:80px; 
    display:inline-block; 
} 
2

背景圖像不支持不重複故有此嘗試後:

.truckIcon{ 
    background: url(../images/icons/favicon.png) no-repeat !important; 
    width:80px; 
    height:80px; 
} 
1

只是單純地改變這個CSS將挑釁工作。

.truckIcon{background-image: url(../images/icons/favicon.png) no-repeat !important; 
 
width:80px; 
 
height:80px; 
 
display:inlin-block; 
 
}