0

Let's say I have my module which adds a slider to the homepage and there are many styles to define. I know I can add the styles in 2 different ways:

  • Adding a css file MyBrand/MyModule/view/frontend/web/css/myfile.css
  • Or adding a less file MyBrand/MyModule/view/frontend/web/css/source/_module.less

Is there a «more correct» way of adding my file? Should I priorize adding .css instead of .less, is there a specific good practice?

In the Magento docs I don't see any specific guideline regarding this.

Just a note: In my case I wanted to use the function .media-width, so I had to chosse using less.

0

Using css or less depends upon your requirement ,refer this for more information about this :- https://devdocs.magento.com/guides/v2.3/frontend-dev-guide/css-topics/css-themes.html https://webkul.com/blog/use-less-magento-2/ https://zemez.io/magento/support/how-to/magento-2-quick-guide-create-custom-css-file/

| improve this answer | |
0

you need to create the file view/frontend/layout/default.xml inside your custom module folder.

Default.xml is for supplement of JS, CSS or Less files on all pages

<?xml version="1.0"?>
<!-- /** * Copyright © 2015 Scommerce Mage. All rights reserved. * See COPYING.txt for license details. */ -->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
   <head>
        <link src="MyBrand_MyModule::custom.js"/>
        <css src="MyBrand_MyModule::custom.css"/>
    </head>
    <body/>
</page>

And very helpful this link refer this :-

https://magehit.com/blog/inset-jscss-or-less-with-your-custom-module-in-magento-2/

Any query let me know..

Thanks.

| improve this answer | |
  • Can you share your thoughts here - magento.stackexchange.com/questions/309714/… – Hamendra Sunthwal Apr 7 at 5:29
  • Thank you for the approach. But it actually doesn't answer my question: should we prioritize including less over css files? Are there any guidelines? Harmendra's answer seems to be a little more explanatory :) – PauGNU Apr 7 at 7:14
  • Please check attached link. – Mohit Patel Apr 7 at 10:26

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.