如何将CSS排除在Magento 2中仅从主页上加载



我想在布局XML文件中添加条件,以允许CSS加载以下方案。

  1. 仅在主页上加载CSS文件。
  2. 通过设备加载CSS(台式机,移动& tab)?

请让我知道如何在布局XML文件中添加条件?

<head>
    <css src="fonts/Lato/lato.css" /> <!-- Should be loaded in website home page only -->
    <css src="css/styles-mobile.css"/> <!-- Should be loaded in mobile devices only -->
</head>

要在主页上加载CSS文件。

您可以在自定义主题中添加以下代码

appdesignfrontend<vendor><theme>Magento_Themelayoutcms_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_configuration.xsd">
    <head>
       <css src="fonts/Lato/lato.css"/>
    </head>
    <body>              
    </body>
</page>

并将lato.css添加到appdesignfrontend<vendor><theme>webcssfontsLato

最新更新