cancel
Showing results for 
Search instead for 
Did you mean: 

Custom CSS in Catergory

Custom CSS in Catergory

Hello you lovely lot!

 

im trying to figure out how i can add a custom CSS file in to certain catergories previously when using magento 1.9 i used to add this code

 

<reference name="head">
    <action method="addCss">
        <stylesheet>css/catergory.css</stylesheet>
        <params>media="all"</params>
    </action>
</reference>

but htis doesnt seem to work or am i putting the CSS file in the wrong place ??

 

/app/design/frontend/themes/themename/web/css/catergory.css

 

any help muchly appreciated

11 REPLIES 11

Re: Custom CSS in Catergory

You need to create xml filie for certain category by prefix as catalog_category_view_ and suffix with category id.

 

Example, If you have category id is 10 then you need to create file catalog_category_view_10.xml

Now keep below content in your xml file,

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <css src="css/catergory.css"/>
    </head>
    <body>
    </body>
</page>

Now your css will be load after clear cache.

If Issue Solved, Click Kudos/Accept As solutions. Get Magento insight from
Magento 2 Blogs/Tutorial

Re: Custom CSS in Catergory

ok thanks for the swift reply but just to clarify whats the path to XML file i need to create  ? and CSS file ?

 

thanks

Re: Custom CSS in Catergory

Xml path for theme level is,

 

app/design/frontend/themes/themename/catalog_category_view_10.xml

CSS path is,

/app/design/frontend/themes/themename/web/css/catergory.css

 

If Issue Solved, Click Kudos/Accept As solutions. Get Magento insight from
Magento 2 Blogs/Tutorial

Re: Custom CSS in Catergory

ok ive tried this and cant seem to get it to work ive put the CSS and the XML in the right place and ran the following commands

 

php  bin/magento cache:clean
php bin/magento cache:flush
php bin/magento setup:static-content:deploy

 

stlll not showing

 

any ideas ?

Re: Custom CSS in Catergory

you need to add xml file name as catalog_category_view.xml i think you have keep name as _id with xml file.

If Issue Solved, Click Kudos/Accept As solutions. Get Magento insight from
Magento 2 Blogs/Tutorial

Re: Custom CSS in Catergory

sorry im getting confused ?

 

ok so ive added file catalog_category_view_8.xml to path

htdocs/app/design/frontend/M2themes/evolution

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <css src="css/laundry.css"/>
    </head>
    <body>
    </body>
</page>

and also added file laundry.css to path

/app/design/frontend/M2themes/evolution/web/css

 

do i need to add anything to Layout Update XML in the catergory i nthe Magento Admin panel ?

Re: Custom CSS in Catergory

Your category id is 8 then your path is perfect, like,

app/design/frontend/M2themes/evolution/Magento_Catalog/layout/catalog_category_view_8.xml

otherwise for all the category,

app/design/frontend/M2themes/evolution/Magento_Catalog/layout/catalog_category_view.xml

 

 

If Issue Solved, Click Kudos/Accept As solutions. Get Magento insight from
Magento 2 Blogs/Tutorial

Re: Custom CSS in Catergory

still nothing :-(

ive checked permissions of the files and ran the commands to clear th cache still nothing im at a loss ?

Re: Custom CSS in Catergory

Kindly check your css file path would be perfect,

/app/design/frontend/themes/themename/web/css/catergory.css

Also check file name for CSS is correct. check

catergory.css not category.css

 

 

If Issue Solved, Click Kudos/Accept As solutions. Get Magento insight from
Magento 2 Blogs/Tutorial