0

I created a custom css file in Vendor/theme/web/css and added css/custom.css to my default_head_blocks.xml file. Im in developer mode but I still ran static content deploy -f. I cleaned/flushed cache. My custom css still does not show up in the head.

What else is there to check for?

0

I Hope this is useful for You,

add your CSS file to

app/code/vendor/module/view/frontend/web/css/mycss.css

mycss.css

 body{
 background-color:green;

 }

Then add CSS File to Your layout File.

app/code/vendor/module/view/frontend/layout/test_index_index.xml

<?xml version="1.0"?>
 <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_layout.xsd">
   <head>
      <css src="css/mycss.css" />
 </head> 
   <body>
     <referenceContainer name="content">
          <block class="vendor\Module\Block\class" template="vendor_Module::class.phtml"/>
     </referenceContainer>  
 </body> 
</page>

Remove this folder

 rm -rf var/cache/*
 rm -rf var/page_cache/*

Remove pub/static

rm -rf pub/static 

Next generate Static Content:

php bin/magento setup:static-content:deploy 

Now, try, Its worked for me.

0
  1. You css file myfile.css should be in : app/design/frontend/{Vendor}/{theme}/web/css/myfile.css

  2. Declared in : app/design/frontend/{Vendor}/{theme}/layout/default_head_blocks.xml

    <?xml version="1.0"?>
    <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../vendor/magento/framework/Module/etc/module.xsd">
        <head>
            <css src="css/myfile.css" />
        </head>
    </page>
    
  3. Remove the CONTENT of : pub/static, generated, var/cache, var/page_cache except the .htaccess

  4. launch : php bin/magento setup:static-content:deploy -f

    It should Work.

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.