0

I have installed magento 2.1.7 with custom theme. Now I want to add a custom css file for modifying theme css.

In that case what's the best practice to add css file.

  1. Create a .less file and include it
  2. Create a .css file and include it in layout
1

You can do using below code in your layout:

<head>
    <css src="Namespace_YourModule::css/custom.css"/>
</head>

You have to delete folders

pub/static

var/

create custom.less In custom.less file file import all less files as per your requirment.

magento\dev\tools\grunt\configs\theme.js

open theme.js file and add your less file under the theme Make sure don't give extensions when you add a file.

For Example

alive: {
        area: 'frontend',
        name: 'Alive/alivetheme',
        locale: 'en_US',
        files: [
            'css/styles-m',
            'css/styles-l',
            'css/custom'
        ],
        dsl: 'less'
    },

deploy static content using command: php bin/magento setup:static-content:deploy

check you css changes.

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.