2017-02-24 22 views
1

我想讓我的svg在我的<i>標記中顯示爲背景圖像。爲了與我的其他代碼保持一致,我使用了<i>標記。如何讓我的SVG顯示在沒有內容的<i>標記中?

如果我沒有在i標籤中包含任何內容,則svg background-image根本無法顯示。我已經嘗試設置<i>標籤的高度和寬度,並且該功能無效。我知道你可以用div來輕鬆做到這一點,但我正在努力使其與此相同。

HTML

<div class="card-panel"> 
    <i class="icon-advanced"></i> 
</div> 

CSS

.icon-advanced { 
    background: url('icon/icon-advanced.svg'); 
    background-repeat: no-repeat; 
    } 
+1

''一個'inline'元件。它不遵守高度和寬度聲明。您需要將其設置爲'block'類型。嘗試在''標籤上添加'display:block;'或'display:inline-block;',您不僅可以設置高度和寬度,還可以查看背景。 – Santi

回答

2

嘗試設置高度之前加入display: inline-block;和寬度

.icon-advanced { 
    background: url('icon/icon-advanced.svg'); 
    background-repeat: no-repeat; 
    background-size: cover; /* stretch the background to cover the whole element */ 

    /* 
     still inline, but has block features 
     meaning height and width can be set 
    */ 
    display: inline-block; 
    height: 20px; 
    width: 20px; 
} 
+0

內聯塊工作謝謝! – RP12

相關問題