How to specify image paths in CSS files?

前端 未结 2 1886
北荒
北荒 2021-02-09 06:15

I\'m using Yii framework and have a CSS file that uses some images for background and similar.

Other PHP code can use Yii::app()->request->baseUrl to prefix the resource

相关标签:
2条回答
  • 2021-02-09 07:06

    The paths to images in CSS files are always relative to the CSS file, not to the page referencing the CSS file.

    So it shouldn't matter that you are using the CSS file in HTML pages at different path depths, as it always looks from the location of the CSS.

    For example, if your CSS file is in /Content/Css and your images are in /Content/Images then you should always reference your images as url(../Images/something.png).

    0 讨论(0)
  • 2021-02-09 07:18

    You may try using semi-relative paths that start with "/". Like "/images/image1.jpg".

    This are always relative to the root of the website.

    Regards

    0 讨论(0)
提交回复
热议问题