0

I have assigned a values to the variable for calling images in CSS like below:

IN CSS file,

    :root {
        --logurl: "domain url";
    }
    
    Then i have passing the variable to background images in css like :
    
    .closeBtn {
        background-image: url("var(--logurl)/assets/images/logo.png");
    }

    But, it is not working. The Domain URL is not binding with the assets/images/logo.png
    Is there anyway to call the variable in css?
Oviya
  • 1

1 Answers1

0

No, It is not possible. If you need to specify the URL, you need to write the entire url() expression. You cannot bind it as url(var(--logurl)), because var(--logurl) itself is considered as an URL. Also the url function will become invalid as substitution never occurs.

Solution

:root {
  --logurl: url("https://imagur.com/abc12.jpg");
}
    
    
.closeBtn {
   background: var(--logurl);
}
Husnul Jahneer
  • 252
  • 2
  • 5