I am trying to create another section and apply a CSS that is in assets folder. But when I put the {{ 'style-section-block.css' | asset_url | stylesheet_tag }}
to the page that I want to apply the CSS to, it affects the other sections as well even though I only put in the section that I want to change.
I am expecting to be able to edit one section page
2
Answers
If you want to apply CSS specific section, first you add a unique class or ID to the section you want to style. After use that unique class or ID in CSS file you can style section. Example is
"my-section" is the unique class name of the this section. You can use that class name add style to section.
According to shopify themes. You can conditionally use the CSS file based on the current page handle or page template. According my thinking you can do this ‘template’ or ‘page.handle’ variable in your theme’s ‘layout’ file. I mean ‘theme.liquid’ file. You can add below code into ‘layout’ file ‘head’ section.
Replace ‘your-specific-template’ with your template name or ‘your-specific-page-handle’ with your page handle name. And remove CSS link from the other sections.
To apply CSS styling to a section in Shopify, you have several options:
Include a Separate CSS File:
Inline CSS within Section File:
{%- style -%}
block to add specific CSS rules directly. This method is useful for section-specific styling.Example:
Dynamic CSS with Liquid:
<style>
block. This approach allows for customizing styles based on user-defined parameters.Example:
These methods provide flexibility in applying CSS styles to sections within your Shopify theme, catering to various styling requirements and scenarios.