Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Root path in css (Jekyll)

I use variable {{ root_url }} to access root path (/) of my website (Jekyll). For eg. I can use it to include the path of external css file.

    <link rel="stylesheet" href="{{ root_url }}/css/main.css">

However in my css/main.css, I cant access {{ root_url }} for eg.

input {
    background: url(/{{ root_url }}/img/search-icon.png);
}

The image is not displayed as {{ root_url }} is not accessible inside css. How can I access {{ root_url }} inside css?

like image 891
2shar Avatar asked May 26 '26 18:05

2shar


2 Answers

You could use a relative path. Since CSS is in a subfolder one level deep, then you could do this:

input {
    background: URL(../img/search-icon.png)
}
like image 53
SEFL Avatar answered May 30 '26 13:05

SEFL


Only file with front matter are Liquid processed by jekyll.

If you want to use liquid in a css, you must add a front matter (even empty) in your css/main.css :

---
# this is an empty front matter that instruct jekyll
# to process this file with liquid
---
input {
    background: url(/{{ root_url }}/img/search-icon.png);
}
like image 41
David Jacquel Avatar answered May 30 '26 12:05

David Jacquel