gpt4 book ai didi

css - 如何自定义 Magento 2 主题?

转载 作者:行者123 更新时间:2023-11-28 15:11:30 29 4
gpt4 key购买 nike

我是 Magento 2 和前端开发的新手 我只知道如何使用 html 和 css,我想在 Magento 2 中自定义空白主题以了解其工作原理,我正在阅读 Magento 2 的文档但是我不知道该怎么做,我想自定义主题我应该更改什么?它是 css 文件还是孔布局(xml)文件?

我尝试通过一些教程来添加 css 文件,但没有任何改变。

这是default_head_blocks.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="css/source/style.css" />
</head>
</page>

这是css文件

.navigation {
background: #40e936;
font-weight: 700;
height: inherit;
left: auto;
overflow: inherit;
padding: 0;
position: relative;
top: 0;
width: 100%;
z-index: 3;
}

最佳答案

要将自定义 CSS 主题文件添加到 Magento 2,您需要:

  1. 在 pub/media/创建文件 custom.css
  2. 转到管理 > 内容 > 配置 > [选择当前使用的主题] > HTML 头 > 脚本和样式表
  3. 输入:<link rel="stylesheet" type="text/css" media="all" href="{{MEDIA_URL}}custom.css" />

但是,Magento 2 中不推荐使用上述方法。在 Magento 2 中,您应该使用 creating a child theme 设置样式。然后编辑从父主题扩展的 CSS 和 LESS 文件。

关于css - 如何自定义 Magento 2 主题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50193365/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com