I am using Magento 2.2.3. In my magneto theme added custom CSS file in the below path: project/app/design/frontend/vendor/theme/web/css/custom.css
I added source file in default_head_blocks.XML file.
after that added a page with following code in HTML content
<div class="freegotest"><span class="tested">count down custom code</span></div>
In custom.css code as
.tested {
color: red !important;
font-size: 20px;
}
By viewing the page source, I can see the custom CSS file included in the header, but the styles are not applying to the text.
2
Answers
Your XML file must be named default_head_blocks.xml instead of default_head_blocks.XML.
Once the name changed, clear cache and static files :
production
, try to re-build static contentAfter updating from 2.1 to 2.3.2, I find out that my custom CSS of swatches Magento_Swatches/web/css/swatches.css content from my custom theme did not merge to styles-m.css & styles-l.css. That caused layout issues in the product detail page.
I can’t find out how to make Magento 2.3.2 merge the custom CSS file to styles-m.css & styles-l.css
So I decide create a new .less file for Magento_Swatches. I created a new file Magento_Swatches/web/css/source/_module.less in my custom theme then move all content of
to
then ran the command
setup:upgrade
After that, the issue was resolved and all custom CSS was merged to styles-m.css & styles-l.css
Look likes Magento 2.3.2 does not allow you to use CSS directly in the module.