8

I want to set path for background image in less file app\design\frontend\vendor\theme\web\<lessfile> in magento2.

closed as off-topic by 7ochem, Marius Aug 23 '16 at 13:32

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions on problems in code you've written must describe the specific problem and include valid code to reproduce it. For help writing short, self-contained syntactically-valid examples, see: http://sscce.org/" – 7ochem, Marius
If this question can be reworded to fit the rules in the help center, please edit the question.

19

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 Mar 14 '17 at 12:27
  • 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 Mar 14 '17 at 13:34
  • 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 Mar 14 '17 at 15:11
  • Thank you ! How about using it this style in _email-extend.less ? and what is the difference with using background: url("@{baseUrl}images/icn.png'); – medmek Oct 21 '18 at 18:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.