In order to create modular style sheets that are not dependent on the absolute location of a resource, authors may use relative URIs. Relative URIs (as defined in [RFC3986]) are resolved to full URIs using a base URI. RFC 3986, section 5, defines the normative algorithm for this process. For CSS style sheets, the base URI is that of the style sheet, not that of the source document.
For example, suppose the following rule:
body { background: url("yellow") }
is located in a style sheet designated by the URI:
http://www.example.org/style/basic.css
The background of the source document's BODY will be tiled with whatever image is described by the resource designated by the URI
http://www.example.org/style/yellow
User agents may vary in how they handle invalid URIs or URIs that designate unavailable or inapplicable resources.
-ms-behavior
会出现异常:( - Philipp Kyeck.banner { background-image: var(--bgimg, url('images/default.jpg')); }
,但是还没有为--bgimg
定义一个值。那么在页面/index.html
上,.banner
将会寻找/images/default.jpg
,但是在另一个页面/about/index.html
上,.banner
将会寻找/about/images/default.jpg
。我认为这非常糟糕。 - chharveybackground: var(--primary-color-background) no-repeat center center url("maps.jpg");
。这在 IOS 和 Safari 中无法正常工作。只有与 CSS 属性配合使用的绝对路径/resources/maps.jpg
能够在 Safari 中正常工作。 - andy