Is there a way to set a common image path for LESS files?

前端 未结 6 1352
面向向阳花
面向向阳花 2020-12-05 03:58

I am using the LESS styling language.

Consider the following CSS:

.side-bg
{
    background:url(../img/layout/side-bg.jpg) top no-repeat;    
}
         


        
6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-05 04:37

    Anton Strogonoff's answer is good but be aware of the Issue @294:

    Using the above which comes straight from the docs, I get url://pathtolessfile/variable I set. Even though I'm trying to set an absolute URL instead of a relative one. For example this works

    @base-url: "../../images/";
    @background-image : url ("@{base-url}/bg.png");
    

    But this does not work

    $base-url: "http://localhost/ns/assets/images/";
    @background-image : url ("@{base-url}/bg.png";
    

    In the latter example, my final source path becomes

    http://localhost/ns/assets/css/libs/http://localhost/ns/assets/images/bg.png
    

提交回复
热议问题