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
asked Jan 28, 2018 at 2:26
Andhi Irawan
9821 gold badge14 silver badges28 bronze badges
-
1You're looking for something like this? magento.stackexchange.com/questions/123664/…Christoph Farnleitner– Christoph Farnleitner2018年01月28日 02:48:28 +00:00Commented Jan 28, 2018 at 2:48
-
@christoph-farnleitner thanks.I have also been looking around magento.stackexchange.com/questions/107482/… just want to know whether the above mentioned method is applicable or not in magento 2.it is different way in magento 2Andhi Irawan– Andhi Irawan2018年01月29日 07:33:09 +00:00Commented Jan 29, 2018 at 7:33
2 Answers 2
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.
answered Jan 28, 2018 at 8:59
circlesix
4,3413 gold badges29 silver badges57 bronze badges
-
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 2Andhi Irawan– Andhi Irawan2018年01月29日 07:34:09 +00:00Commented Jan 29, 2018 at 7:34
-
1yeah. 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– circlesix2018年01月29日 18:21:54 +00:00Commented Jan 29, 2018 at 18:21
A little bit tricky, in the inside content field you can use like this :
<style xml="space"><!--
/* your css snippet here */
--></style>
Andhi Irawan
9821 gold badge14 silver badges28 bronze badges
-
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 AnsyoriAndhi Irawan– Andhi Irawan2019年04月29日 10:49:43 +00:00Commented Apr 29, 2019 at 10:49
default