LESS importing CSS and relative paths

后端 未结 4 610
别跟我提以往
别跟我提以往 2021-01-03 23:25

I am using LESS to organize and import all my CSS files. I am also using Twitter Bootstrap which I integrated inside my style.less. It works fine like below however when I u

4条回答
  •  不知归路
    2021-01-04 00:11

    When running lessc use the --relative-urls flag.

    lessc --relative-urls
    

    It's poorly documented, but by default it is false which means that all @imported files will maintain their urls (e.g. background-image, font-face, etc) as they are. This is because less was already doing this and many users expect it to leave their urls alone.

    When the relative-urls flag is used, lessc rewrites all of the urls according to the location of the less/css file being imported.

    Example

    /dir1/style/main.less

    // if you don't include (less) lessc will leave bootstrap
    //   as an @import at the top of the lessified css file
    @import (less) '../bootstrap/bootstrap.min.css';
    

    /dir1/lib/bootstrap/bootstrap.min.css

    background-image:url("../img/bs-img.gif");
    

    Result:

    /dir1/style/main.css

    background-image:url("../bootstrap/img/bs-img.gif");
    

提交回复
热议问题