2017-12-27 14 views
2

Können Sie mir sagen, wie man Bild mit SCSS dynamisch hinzufügen?Blockquotebild dynamisch mit SCSS hinzufügen

Hinweis:

Ich habe svg Bild auf diesem Weg: assets/icon/left-quote.svg

Dies ist, was ich brauche.

enter image description here

Hier können Sie sehen, wo es aus dem Backend kommt (d. Tags).

enter image description here

Antwort

5

Sie können die ::before Pseudo-Selektor wie folgt:

blockquote { 
 
    text-align: center; 
 
    font-weight: bold; 
 
    font-style: italic; 
 
    color: darkblue; 
 
} 
 

 
blockquote::before { 
 
    display: block; 
 
    width: 1.5em; 
 
    height: 1.5em; 
 
    margin: 1em auto; 
 
    content: url("https://upload.wikimedia.org/wikipedia/commons/2/25/Quote_left_font_awesome.svg"); 
 
}
<blockquote> 
 
    Parties prenantes de cette organisation (marchande ou non-marchande) par rapport aux attentes et besoins 
 
</blockquote>

machen mehr SCSS-like:

blockquote { 
    text-align: center; 
    font-weight: bold; 
    font-style: italic; 
    color: darkblue; 

    &::before { 
    display: block; 
    width: 1.5em; 
    height: 1.5em; 
    margin: 1em auto; 
    content: url("https://upload.wikimedia.org/wikipedia/commons/2/25/Quote_left_font_awesome.svg"); 
    } 
} 
+0

Es arbeitet als ich URL benutzt habe. Aber das funktioniert nicht. Weißt du, warum? 'content: url ('./ assets/icon/left-quote.svg');' – Sampath

+0

Können Sie mir sagen, wie man es mithilfe der Projektdatei als ''./assets/icon/left-quote.svg'' lädt ? – Sampath

+0

Ich weiß nicht, wie Ihr Projekt aufgebaut wird, was wo verpackt wird, von welchem ​​Ort aus Sie referenzieren. Wenn alles andere fehlschlägt, codiert base64 das SVG und verwendet einen Daten-URI. –