CSS attr()与url路径连接

CSS attr()与url路径连接,css,concatenation,attr,Css,Concatenation,Attr,如何将CSS attr()选择器与url()字段中的静态文本连接起来 我使用的HTML: <div image='/Require/static.png'></div> //Example 2 <div image='static.png'></div> //Example 3, 4, 5 因此-如果可能-我如何实现这一点?不可能从两个或多个字符串中创建复合url()值。传统的url()值甚至不是一个正确的CSS函数(请参阅-这意味着您甚至不能使

如何将CSS attr()选择器与url()字段中的静态文本连接起来

我使用的HTML:

<div image='/Require/static.png'></div> //Example 2
<div image='static.png'></div> //Example 3, 4, 5

因此-如果可能-我如何实现这一点?

不可能从两个或多个字符串中创建复合
url()
值。传统的
url()
值甚至不是一个正确的CSS函数(请参阅-这意味着您甚至不能使用自定义属性执行此操作),在中定义的
url()
的正确CSS函数版本只接受一个字符串。1

您可以在
内容
声明中连接多个字符串,但不能在CSS中连接多个字符串



1由于
url()
接受单个字符串,这意味着单个
attr()
可以用作url值,如
attr(图像url)
。。。除了。

你能把你的HTML和图像标签一起发布吗?CSS是很容易解释的,不需要HTML来理解。更新后,请看postIs this SVG,或者你只是为了好玩而使用了
?至少要阅读前面的其他评论,感谢你的回答和提供的文档!
//image attribute contains the image name (and prefix location when needed, see example 2)
div[image]:before {
    background-image: url('/Image/static.png'); //Works
    background-image: url(attr(image)); // Works
    background-image: url('/Image/' attr(image)); //Fails
    background-image: url('/Image/' #attr(image)); //Fails
    background-image: url('/Image/' {attr(image)); //Fails
    }