Magento 2 CSS – CSS Not Loading in Owl Carousel

cssjavascriptmagento-2.1magento2owl-carousel

hello guys i am trying to use owl carousel in phtml file in console it shows error regarding css
Following is my default_head_block.xml file which is a layout file

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>        
    <meta name="viewport" content="width=device-width, initial-scale=1"/>

    <css src="web/css/owl.carousel.css" /> 
     <css src="web/css/owl.theme.css" /> 


</head>
</page>

Following is my default.xml file through i am calling phtml file

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
<body>
    <referenceContainer name="content">
        <block class="Magento\Framework\View\Element\Template" name="slider_test" template="Magento_Theme::slider.phtml" after="-" />
    </referenceContainer>
    <referenceBlock name="logo">
        <arguments>
            <argument name="logo_img_width" xsi:type="number">148</argument>
            <argument name="logo_img_height" xsi:type="number">43</argument>
        </arguments>
    </referenceBlock>
</body>
</page>

Following is my slider.phtml file in which i am calling owl carousel

 <div class="owl-carousel" id="car">
 <div> Your Content </div>
 <div> Your Content </div>
 <div> Your Content </div>
 <div> Your Content </div>
 <div> Your Content </div>
 <div> Your Content </div>
 <div> Your Content </div>
 </div>

<script type="text/javascript">
require([
    'jquery',
    'owlcarouselslider'
    ], function ($) {
          $("#car").owlCarousel();
});
</script>

Following is output
enter image description here

following is error which showing in console

enter image description here

Best Answer

This error usually shows up when static content is not correctly generated by Magento. It can show also show up when using a vanilla Magento installation and is not necessarily related to a theme or installed extension.

In most cases, this error disappears once you setup the correct permissions and generate the static content for your store.

Solution 1.

  1. Correctly set Magento permissions by following the instructions under Basic Permissions Setup below:

https://support.weltpixel.com/hc/en-us/articles/115001868933-How-to-set-Magento-2-permissions-and-avoid-installation-errors

  1. Go to Developer mode and then to Production mode. This action performs a cache cleanup, compiles your code and generates the static content.

https://support.weltpixel.com/hc/en-us/articles/115004436368-How-to-set-Magento-2-Developer-and-Production-Mode-via-SSH

  1. Generate static content for each locale if you are using a locale different to en_US (nl_NL, en_GB)

example: php bin/magento setup:static-content:deploy -f en_GB

If this doesn't help, there may be an additional issue related to the pub/static folders caused by the missing .htaccess file.

Solution 2.

To fix this issue,

  1. Go to file path pub/static/

  2. Check whether the .htaccess file is available (hidden file - Press ctrl+H to view it).

  3. If not available, based on the Magento version get the .htaccess file in the file path pub/static/and move it into your server.

  4. Finally, clear your browser and Magento cache and check again.

I hope this will help