2

enter image description here

enter image description here

Hi guys, I use the css3 variable want to set the background img url dynamic, but it doesn't work for me. but it's worked if I set a color value to a variable and use it, and if it's in backgroud attribute, it's just like url(var(--src)) and it didn't work... how should I do?

because I want upload the pictures of my project to a cloud server, and reference the image link from the server. but in some cases I need change the server domain and I don't want change it one by one in all referenced files. so my plan is create a base css style, and all others css file need import this, in this base css, declare a variable to save the server domain, and then other css files can read this var. but it doesn't seem to work. Any ideas guys?

Myron Von
  • 21
  • 1
  • 2

1 Answers1

0

You can use the following

:root {
  --url: url("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQCRdy-xqdYAs_g95P-gsnPcw8FgUYK-SqSq814BY6i55piXZrG"); 
  
}

.test {
  background: var(--url);
  padding:50%;
  background-repeat:no-repeat;
}
<div class="test">
</div>
pencil a
  • 91
  • 2