Magento2: Como localizar a imagem de fundo no arquivo .less? [fechadas]


8

Eu quero definir o caminho para a imagem de fundo em menos arquivo app\design\frontend\vendor\theme\web\<lessfile>no magento2.

Respostas:


23

First add image in app\design\frontend\vendor\theme\web\images folder and write css as below:

background: url('@{baseDir}images/icon_sprite.png');

after add new image run command as below:

- php bin/magento cache:clean
- php bin/magento setup:static-content:deploy

This is not working for me in Magento 2.1.4. Does this only apply to production mode or should this work in developer mode as well?
Giel Berkers

1
This will work in both mode, just you have to run php bin/magento setup:static-content:deploy command after add image in app\design\frontend\vendor\theme\web\images folder. if still not working remove var/view_preprocessed folder.
Dipesh Rangani

1
Thanks for the feedback. Turned out that my problem was elsewhere. Something to do with corrupt PNG files. Yeah I know, long story... your answer is still correct though. However, you could add that it in some cases it might be necessary to define @baseDir in your themes' theme.less. By default the variable is set to ../.
Giel Berkers

Obrigado ! Que tal usá-lo nesse estilo em _email-extend.less? e qual é a diferença com o usobackground: url("@{baseUrl}images/icn.png');
medmek
Ao utilizar nosso site, você reconhece que leu e compreendeu nossa Política de Cookies e nossa Política de Privacidade.
Licensed under cc by-sa 3.0 with attribution required.