Magento 2 – How to Add a CSS Class to a CMS Static Block

cms-blockmagento2

Currently working on a magento homepage layout that includes a static block widget through the CMS (as opposed to referencing it through XML layouts) but no matter what I do I can't alter the classes generated when rendering.

The widget currently renders the following tag

<div class="widget block block-static-block"> </div>

I have tried adding it through the htmlClass argument through a referenceblock to the widget ID in layout XML but that's not working. Any other ideas?

Best Answer

Use argument of css_class You can call your block directly from the xml layout(Thats what i did at magento 1.x)

i Guess you can do it on phtml but thats not was approach for my opinion

<block class="Magento\Catalog\Block\Product\View\Description" name="product.info.sku" template="product/view/attribute.phtml" after="product.info.type">
<arguments>
    <argument name="at_call" xsi:type="string">getSku</argument>
    <argument name="at_code" xsi:type="string">sku</argument>
    <argument name="css_class" xsi:type="string">my-class</argument>//here
</arguments

this is from the official magento 2 docs

http://devdocs.magento.com/guides/v2.0/frontend-dev-guide/layouts/xml-manage.html

Please read it before you asking and go directly for SE

Happy coding Mate