0

I saw an article that asked the same question a few years ago, but I couldn't solve it after seeing the article, so I want to ask the question again.

I want to get the css background-image url value as an HTML data-attribute and use it.

.thumb{
  background-image: attr(data-background);
}
<div class="thumb" data-background="https://via.placeholder.com/300"></div>
chi
  • 9
  • 2
  • What is the problem? you don't see the image? Is this all the css code? – Sfili_81 May 24 '22 at 08:22
  • According to https://caniuse.com/?search=attr attr only works for the CSS content property in current browsers. – A Haworth May 24 '22 at 08:23
  • So am I. I am getting the data background from div.thumb in html file and using it for each div.thumb background image source in css file. – chi May 24 '22 at 08:34

0 Answers0