html - 如何在 CSS 内容属性中混合 url 字符串和属性值?

标签 html css

<分区>

我需要使用 CSS content 属性和 :before 伪选择器在它旁边显示对应于每个元素的图像。

我如何以有效的工作方式做类似下面的事情:

content: url("http://example.com/images/" + attr(title));

在 URL 显示图片

 "http://example.com/images/523452345"

上面的不行!

最佳答案

那是不可能的,这是规范,你不能把 attr() 放在 url() 里面,它们只能互相跟随。

content: normal | none | 
         [ <string> | <uri> | <counter> | attr() |
           open-quote | close-quote | no-open-quote | no-close-quote ]+ | inherit


div:before {
    content: url("http://example.com/image.jpg") attr(title);
}

关于html - 如何在 CSS 内容属性中混合 url 字符串和属性值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23815657/

相关文章:

javascript - 如何在单击按钮时滚动到选定的选项?

javascript - 导航到页面的某个部分

css - 针对不支持具有功能查询的 CSS 网格的浏览器

html - 悬停时阻止 Nav div 移动

css - 如果我输入媒体 ="screen"和不输入媒体有什么区别

css - 标签位置在不同浏览器之间变化

html - CSS 选择紧跟在具有不同属性值的元素之后放置的所有元素

javascript - 将每次迭代中的 html 附加到单个 div

html - 悬停时 CSS div 宽度悬垂

css - 为什么响应停止