在magento中仅从xml的主页添加css

时间:2012-11-16 06:47:09

标签: css xml magento

想要包含仅适用于xml文件主页的css文件 试过这个:

<cms_index_index>
 <action add css>
   .
   .
 </action> 
</cms_index_index>

在local.xml中使用它会在每个cms页面中添加特定的css 任何想法?
在此先感谢。

5 个答案:

答案 0 :(得分:9)

在cms主页中有Design(布局更新XML) 使用以下代码

<reference name="head">
 <action method="addItem"><type>skin_js</type><name>js/myjavascript.js</name></action>
</reference>

答案 1 :(得分:4)

此解决方案适合我

<cms_index_index translate="label">
    <label>CMS Home Page</label>
             <reference name="head">
                  <action method="addCss">
                     <stylesheet>
                               css/custom.css /*This is ur css path*/
                     </stylesheet>
                  </action>
             </reference>
</cms_index_index>

答案 2 :(得分:1)

试试这个

<cms_index_index>
    <reference name="your cms identifier for home page">
        <action method="addCss"><stylesheet>your path/your css file name</stylesheet></action>
    </reference>
</cms_index_index>

请在local.xmlpage.xml

中使用此代码

我不是100%确定代码是否正常工作

答案 3 :(得分:1)

结合我最近发现的@ Leo的answer以及another blog post,这里只是一个代码片段,只为一个页面添加自定义css。

<reference name="head">
    <action method="addCss">
        <stylesheet>css/custom.css</stylesheet>
    </action>
</reference>

与@Leo提到的相同的说明。

答案 4 :(得分:1)

以上建议在Magento 1.7中无效,空白主题。有用的是:

<reference name="head">
    <action method="addCSS">
      <type>css/master.css</type>
      <stylesheet>media="all"</stylesheet>
    </action>
  </reference>

这产生了以下代码

<head><link rel="stylesheet" type="text/css" href="http://myshop.com/shop/skin/frontend/mytheme/blank/css/master.css" media="all"></head>

我将此代码放入我主题的local.xml中。