I am trying to add css on certain URL Liquid Shopify. Only on that subpage I need that element in different style than other pages.
I found in the other liquid code some examples attached inside, but it is not working. Those are my examples I’ve tried:
The element I would like to style has no unique class or id.
<style>
{% if page.url == 'fullUrl' '%}
#someEmelent {margin: 0 auto}
{% endif %}
{% if page.url == '/subpage/subpage' '%}
#someEmelent {margin: 0 auto}
{% endif %}
{% if page.url == '/subpage' '%}
#someEmelent {margin: 0 auto}
{% endif %}
</style>
I have tried other things in pure CSS, like:
@document url("http://www.example.com/subpade/") {
#someEmelent {margin: 0 auto}
}
2
Answers
You may use the request object:
https://shopify.dev/docs/themes/liquid/reference/objects/request#request-path
So something like this should work:
Another way would be to create and apply a specific template to your page.
Then you might add a specific class to body and use it in your CSS file.
I think what you want is to base your CSS on template title. ex: if you want to a CSS class for a specific collection your can use :
you can change collection with any template name