1

I would like to type the following command in a css file.

background: #2c001e url(file:///home/user/.local/share/backgrounds/mypic.jpg)

However, I don't want to explicitly declare the user path /home/user/ but instead use ~ and $HOME in its place. I discovered they did not work, i.e.

background: #2c001e url(file://~/.local/share/backgrounds/mypic.jpg)
background: #2c001e url(file://$HOME.local/share/backgrounds/mypic.jpg)

What is the correct syntax that I should use?

The context for using the above command is described here.

Sun Bear
  • 2,302
  • The URL with $HOME should work fine. You just forgot a / after $HOME. – BeastOfCaerbannog Oct 01 '19 at 15:45
  • @user3140225 I tried background: #2c001e url(file://$HOME/.local/share/backgrounds/mypic.jpg) but it still did not work...puzzled? I ran Alt+F2+r+return to refresh the GDM but they still did not work. – Sun Bear Oct 01 '19 at 15:58
  • The first command, background: #2c001e url(file:///home/user/.local/share/backgrounds/mypic.jpg), works? – BeastOfCaerbannog Oct 01 '19 at 16:06
  • 2
    As I understand, "file:///" is interpreted by the internet browser, while ~ and $HOME are system variables. The browser does not know about them. So in this case you should always use the full path. Maybe I'm wrong? – schrodingerscatcuriosity Oct 01 '19 at 16:06
  • @user3140225 Yes. – Sun Bear Oct 01 '19 at 16:16
  • @SunBear I think that @guillermo-chamorro is right. What confused me is that I tried opening a file in Chrome by running google-chrome file://$HOME/path/to/file in the terminal and it worked fine. But it worked fine exactly because I ran it in the terminal, which can "convert" the $HOME system variable to my actual home path. When the css file is read, it's the browser that does the reading, which, as guillermo said, does not know about system variables. – BeastOfCaerbannog Oct 01 '19 at 16:31
  • @guillermochamorro I wonder how css programmer typically handle such a requirement? – Sun Bear Oct 01 '19 at 16:37
  • 1
    It's not a requirement, web development is an "independent" system that does not need a pecific OS to work, for example the web browser. In this case, what you have to take into account is what and how the browser parses files, which is the same in any OS. – schrodingerscatcuriosity Oct 01 '19 at 16:51
  • 1
    @SunBear Web developers also use javascript for such tasks. See this article for example. – BeastOfCaerbannog Oct 01 '19 at 17:09
  • @user3140225 Thanks. In my case, I think it may have to use the resource command (leveraging on GNOME). – Sun Bear Oct 01 '19 at 18:05

0 Answers0