0

In Magento 1 we can add inline CSS from admin Layout Update XML like this :

<reference name="head">
 <block type="core/text" name="custom_css">
  <action method="setText">
      <text><![CDATA[
         <style  type="text/css">
            .my-class  {
                color: red;
            }
         </style> ]]>
    </text>
  </action>
 </block>
</reference>

how can this be implemented in Magento 2 admin Layout Update XML?

I've tried it in Magento 2.2 but it did not work

1

This is not currently possible in Magento 2. You can add in CSS classes with XML (the example that @Christoph Farnleitner), but not actual CSS itself.

  • thanks.i just want to know whether the above mentioned method is applicable or not in magento 2.so, it is different way in magento 2 – Andhi Irawan Jan 29 '18 at 7:34
  • 1
    yeah. You might come across some xml in M2 that has "style" like attributes in them. These are the UI Component system and they have things like "width" and such are elements that can be defined. So at first it might look like you can, but this is just trickery on Magento's part that only works with that system. You can now load css on just the pages you want with xml, that is handy to reduce code on the site. – circlesix Jan 29 '18 at 18:21
1

A little bit tricky, in the inside content field you can use like this :

<style xml="space"><!--
/* your css snippet here */
--></style>
  • So you have to go through the Content section? If through the XML Update Layout, can it work too? Just curious. If can't, through Content it's more than enough. Thank you Bang Ansyori – Andhi Irawan Apr 29 at 10:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.