首页 > 解决方案 > 自定义 CSS 未在某些页面上加载 - 特别是那些带有表单的页面?

问题描述

所以我安装了 Magento,扩展了空白主题,并加入了一些自定义 CSS……CSS 可以在某些页面上工作,例如主页、隐私政策和目录页面,但在其他页面上不起作用。在有表格的页面上似乎有问题,例如联系表格、订单和退货以及高级搜索页面。当我查看源代码时,页面上会显示 CSS 参考。

我已将 CSS 参考放在内容 > 设计 > 配置下的 HTML 头部部分中。我也将参考放在 default_head_blocks 中。我试过刷新 Magento 的缓存并擦除 var/cache 文件夹。

default_head_blocks:

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <head>
        <css src="[site].com/pub/media/kwesteb.css" media="screen and (min-width: 1px?)" />
        <css src="css/styles-m.css"/>
        <css src="css/styles-l.css" media="screen and (min-width: 768px)"/>
        <css src="css/print.css" media="print"/>
        <meta name="format-detection" content="telephone=no"/>
    </head>
</page>

我希望 CSS 显示在所有页面上,但是它不会显示在具有某种联系形式的页面上。

标签: cssmagento2

解决方案


You've set the css file up wrongly and it's trying to be applied twice. You're trying to find it at https://kwesteboutique.com/contact/pub/media/kwesteb.css and https://kwesteboutique.com/pub/static/version1569869554/frontend/Kweste/KwesteBtq/en_US/kwesteboutique.com/pub/media/kwesteb.css The first url is because of the entry in design -> configuration, just delete that. The second is the broken reference in the default head blocks xml file.

Please move it to the correct place detailed below and fix the default_head_blocks.xml entry.

The file needs to be in app/design/frontend/<vendor>/<theme>/css

Change the xml file entry to: <css src="css/kwesteb.css" media="screen and (min-width: 1px?)" />

CSS files should be attached to a theme or a module not in pub/media.

If you are in developer mode, clear the cache load the page. If you are in production mode you'll need to deploy static content. The default way being php bin/magento setup:static-content:deploy, if you use a custom script or something to deploy the content like that, do that instead.

Some advice in debugging this kind of issue. Check the inspector, if you have an error it's more than likely according to Magento, you've done something wrong. If it's CSS like this, you have MIME type errors, often that means it's not being referenced correctly or you have an url issue. If you look at the second url I mentioned that you have on the page, that refers to a file structure. ignore the version bit and then you can follow the structure from pub. If that's wrong you need to fix where the file is. Also remember that most if not all server systems are case sensitive on the file and folder names.


推荐阅读