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

asked Jan 28, 2018 at 2:26
2

2 Answers 2

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.

answered Jan 28, 2018 at 8:59
2
  • 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 Commented Jan 29, 2018 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. Commented Jan 29, 2018 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>
Andhi Irawan
9821 gold badge14 silver badges28 bronze badges
answered Apr 23, 2019 at 14:28
1
  • 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 Commented Apr 29, 2019 at 10:49

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.